XSLTProcessor->transformToUri() function

Hello everyone...

I have just a xml and a xsl file, and so due to compatibility with some browsers I wanted to unify them in a html result file. In this case I thought about transformToUri using a simple php file.
I obtain correctly the html output file but the mess is in the output file the processor puts also at the end of the file the text contents of xml file... so I'm here asking you if there is maybe some configuration parameters to check or what?

I have done that under Windows XP Pro + Apache + PHP 5 with libxslt included

Any idea?

Thanks a lot in advance!
Ciao
Luigi
npuleioAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
Hi npuleio,
> e mess is in the output file the processor puts also at the end of the
> file the text contents of xml file

likely this mess is a result of the default templates processing for the text nodes
(they fall throught)

can you post your XML and XSLT, so we can have a look?

Cheers!
0
npuleioAuthor Commented:
Hello Gertone,

sure, there is:

the XML file:

<lastanzadiluigi>
  <titolo>La Stanza di Luigi</titolo>
  <logo>logoarea.jpg</logo>
  <links>
    <link>
      <ref>main.xml</ref>
      <text_ref>La stanza di Luigi</text_ref>
    </link>
    <link>
      <ref>main.xml</ref>
      <text_ref>L'angolo del programmatore</text_ref>
    </link>
    <link>
      <ref>main.xml</ref>
      <text_ref>L'arte dell'Interior Design</text_ref>
    </link>
    <link>
      <ref>main.xml</ref>
      <text_ref>Tempo libero</text_ref>
    </link>
    <link>
      <ref>main.xml</ref>
      <text_ref>Links</text_ref>
    </link>
  </links>
  <articoli>
    <articolo>
      <data_art>Thursday December 1, 2005</data_art>
      <autore>Luigi</autore>
      <titolo>Presentazione</titolo>
      <testo>Informatica e Interior Design, un connubio di passione. Entrambe percorrono una strada comune: la creativita.
      Occupano spazi immensi della nostra realta, ed in questa stanza, che e questo sito inteso tale, ci si prefigge il
      desiderio di espandere ulteriormente questi spazi, riempiendoli di scambi di opinioni e notizie nonche consigli.
      Il tutto ricordando che alla base di questa stanza c'e sempre la passione e ricordando anche i vantaggi positivi
      di una giusta applicazione sul piano pratico nella realta di questi due campi.</testo>
    </articolo>
    <articolo>
      <data_art>Thursday December 1, 2005</data_art>
      <autore>Luigi</autore>
      <titolo>asdasdasfsadd</titolo>
      <testo>sdfasdfasdasdasfasfasddfasd</testo>
    </articolo>
  </articoli>
</lastanzadiluigi>


the XSLT file:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="iso-8859-1" indent="yes"/>
  <xsl:template match = "/">
    <html>
      <head>
         <style type="text/css" media="screen">@import "lastanzadiluigi.css";</style>  
      </head>
      <body>
        <div id="container">
          <!-- inizio riquadro contenitore -->
          <div id="container_inside">
           <!-- inizio riquadro titolo -->
            <div id="titolo">
             <div id="titolo_inside">
               <h1><span>
                 <xsl:value-of select=".//titolo"/>
               </span></h1>
             </div>
            </div>
           <!-- fine riquadro titolo -->
           <!-- inizio riquadro leftcolumn -->
           <div id="rightcolumn">
             <!-- inizio riquadro links -->
             <div id="linklist">
                    <div id="linklist_inside">
                 <div id="list_select">
                   <h3 class="select"><span>Select a Design:</span></h3>
                   <ul>
                     <xsl:for-each select=".//link">
                       <li><a>
                         <xsl:attribute name="href">
                           <xsl:value-of select=".//ref"/>
                         </xsl:attribute>
                         <xsl:value-of select=".//text_ref"/>
                       </a></li>
                     </xsl:for-each>
                   </ul>
                 </div>
               </div>
             </div>
             <!-- fine riquadro links -->
           </div>
           <!-- fine riquadro leftcolumn -->
           <!-- inizio riquadro main -->
           <div id="maincolumn">
             <xsl:for-each select=".//articolo">
               <div id="riquadroarticolo">
                 <div id="articoloinside">
                   <p id="titolo_art"><xsl:value-of select=".//data_art"/></p>
                   <p id="titolo_art"><xsl:value-of select=".//autore"/></p><br/>
                  <p id="articolo"><xsl:value-of select=".//testo"/></p>
                 </div>
               </div>
             </xsl:for-each>
           </div>
           <!-- fine riquadro main -->
           <!-- inizio riquadro footer -->
           <div id="fondo">
           </div>
           <!-- fine riquadro footer -->
          </div>
          <!-- fine riquadro contenitore -->
        </div>
      </body>
    </html>
    <xsl:apply-templates />
  </xsl:template>
</xsl:stylesheet>

As I looked around examples in the web I thought they are right but maybe I could have forgotten something little if you say it could be a mess somewhere in the code...at least with 4 or more eyes instead of 2 ones that would be more helpful...

thanks again! :-)
Ciao
Luigi
0
Geert BormansInformation ArchitectCommented:
near the end of the stylesheet you have to remove the apply-templates

    <xsl:apply-templates />
  </xsl:template>
</xsl:stylesheet>

should be

   </xsl:template>
</xsl:stylesheet>
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

npuleioAuthor Commented:
Uhm but in the examples around the web I read that <xsl:apply-templates />, so I thought it's used because I have <xsl:template-match="/"> as like "search all nodes 'till a correspondence is found then apply the template to the result file"...if I'm wrong, then could explain me that difference?

Thanks again
Ciao.
Luigi
0
Geert BormansInformation ArchitectCommented:
Luigi buona serata,
(hope that is corret :-)

what happened is the following
In the template for the root element you do all the processing
(which is OK)
but at the end you push the childnodes to the templates

you don't have any templates, so the default processing comes into play
that basically shows the text nodes and drops the tagging
That is what you saw happening

since you don't need to push all the childnodes to the templates,
simply dropping this line solves your problem

ciao

Gertone
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
npuleioAuthor Commented:
Grazie Gertone!

now I've understand something more about having templates... I guess I'll have to get back my old XML book and read more about templates hehe

And lemme guess you're half-italian, am I right? ;-) In fact it was right that "buona serata" so you too :-)

I'm from Italy, precisely around Milan :-)

Ciao!
Luigi
0
Geert BormansInformation ArchitectCommented:
Luigi,

I will explain in some detail what apply-templates is about.

I have this example XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <node>
        <content>text</content>
    </node>
</root>

and this example XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="iso-8859-1" indent="yes"/>
  <xsl:template match = "/">
      <xsl:apply-templates/>
  </xsl:template>
    <xsl:template match="root">
        <exroot><xsl:apply-templates/></exroot>
    </xsl:template>
    <xsl:template match="node">
        <exnode>
            <xsl:apply-templates select="content"/>
        </exnode>
    </xsl:template>
    <xsl:template match="content">
       <xsl:value-of select="."/>
    </xsl:template>
  </xsl:stylesheet>

see what happens when you run it
0
Geert BormansInformation ArchitectCommented:
usually the template for match="/" is the starting point (it is always good to have one)

templates are islands that have rules
XSLT is a rule based programming language

if the rules described in the match statement are triggered
(because a nodeset pushed to the templates is looking for something to match)
the actions inside the templates get triggered

in the example you have
 <xsl:template match = "/">
      <xsl:apply-templates/>
  </xsl:template>
which basically means that all child nodes of the document element are pushed to the templates
basically that is the root element

this root element node is then picked up by template match="root"
inside the root template we have
    <xsl:template match="root">
        <exroot><xsl:apply-templates/></exroot>
    </xsl:template>
what happens there is: we create a XML node <exroot>
and push the child nodes to the templates
note: this is not just the node element, but also the surrounding white-space text nodes
the default processing for text nodes is being copied to the output tree
meaning that you will see the newlines and spaces copied in the output

the template that picks up the node element
does something more special
it creates the <exnode> element and pushes only the childnodes of type element, name 'content' to the templates
yes, you can be selective in your apply-templates <xsl:apply-templates select="content"/>
this has as an effect that the white-space nodes around "content" are not copied (not processed)

That is the technique, I hope this is now clear.
I prefer this very XSLT like way of processing over trying to solve everything in one template

I hope by now you understand why you didn't need it

I am far from half Italian,
but have quite some friends there
my nickname 'Gertone' by the way has been given to me years ago by some friends that could not pronounce 'Geert' :-)
ciao

Gertone
0
npuleioAuthor Commented:
Now I got it!
When I'll need to remember around templates I'll read just your answer :-)

Thanks Gert!
Buona serata!
Ciao, Luigi
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.