[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XSLT2 processing question


Subject: Re: [xsl] XSLT2 processing question
From: "andrew welch" <andrew.j.welch@xxxxxxxxx>
Date: Tue, 23 May 2006 14:06:55 +0100

What you are seeing is because of the "default templates" or "built in
templates" and is a FAQ:
http://www.dpawson.co.uk/xsl/sect2/defaultrule.html

It's pretty well covered there, not much to add.

On 5/23/06, Georg Hohmann <georg.hohmann@xxxxxxxxx> wrote:
Hello,

till today i thought that i was no beginner with xslt anymore but now
i'm not sure about. I thought i knew how xsl processes data but that
was wrong (i guess). I read many basic informations about the
processing structure but i didn't get right idea what in my thinking
is wrong. So i bend my knees and ask the experts ;-)

What i got is something like this as the source:
---------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<customers>
   <info>This is data about customers</info>
   <person>
      <name>
            <first>John</first>
            <last>Doe</last>
      </name>
      <idnr>123</idnr>
   </person>
   <person>
      <name>
            <first>Tom</first>
            <last>Test</last>
      </name>
      <idnr>456</idnr>
   </person>
   <person>
      <name>
            <first>Edna</first>
            <last>Example</last>
      </name>
      <idnr>789</idnr>
   </person>
</customers>
---------------------------------------------------------------------

My Stylesheet looks like this:
---------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output name="out" method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
   <xsl:template match="/">
      <xsl:result-document format="out" href="result.xml">
         <adress>
            <xsl:apply-templates/>
         </adress>
      </xsl:result-document>
   </xsl:template>
   <xsl:template match="//name">
      <firstname>
         <xsl:value-of select="first"/>
      </firstname>
   </xsl:template>
</xsl:stylesheet>
---------------------------------------------------------------------

What i *want* to have is this:
---------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
   <adress>
      <firstname>John<firstname>
      <firstname>Tom<firstname>
      <firstname>Edna<firstname>
   </adress>
---------------------------------------------------------------------

But the result i get from my stylesheet is this:
---------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<adress>
   This is data about customers

      <firstname>John</firstname>
      123


<firstname>Tom</firstname> 456


<firstname>Edna</firstname> 789

</adress>
---------------------------------------------------------------------

What am I doing wrong? I thought the stylesheet would do the
following: Go to the root element (match="/"), generate my root
("adress") and add the results of the following template
(apply-templates). The next template searches for the node "name"
everyware in the source ("//name"), and for each nodes it finds it
appends a node called "firstname" with the value of "first".

Well, obviously this is not (exactly) what it does. Why are the values
of "info" and "idnr" also in the output? I know this is an issue about
how xslt processes data and it's a real beginner scenario, so i'm
sorry to waste your time with it. I'm not (only) interested in the
right solution to get the result i want but also for an explanation of
where my thinking is wrong.

I would be happy if someone could give me a hint ...

Regards,
G. Hohmann


Current Thread
Keywords