xsl-list
[Top] [All Lists]

RE: [xsl] XSLT2 processing question

2006-05-23 06:36:19
You could ask this equally of XSLT 1.0.

You haven't defined a template that matches idnr, so your stylesheet behaves
as if you had defined

<xsl:template match="idnr">
  <xsl:apply-templates/>
</xsl:template>

Look in the spec for "built-in template rules".

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Georg Hohmann [mailto:georg(_dot_)hohmann(_at_)gmail(_dot_)com] 
Sent: 23 May 2006 13:39
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] XSLT2 processing question

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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>