?
Solved

XSLTProcessor->transformToUri() function

Posted on 2006-04-03
9
Medium Priority
?
290 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:npuleio
  • 5
  • 4
9 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16362940
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
 

Author Comment

by:npuleio
ID: 16363022
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16363065
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:npuleio
ID: 16363129
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
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 16363172
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
 

Author Comment

by:npuleio
ID: 16363315
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16363352
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16363501
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
 

Author Comment

by:npuleio
ID: 16363851
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question