Hi, here is my xml file order.xml <?xml version="1.0"?> <?xml:stylesheet type="text/xsl" href="node.xsl"?> <order number="1234"> <date>2001/1/1/</date> <customer id="8888">Company A</customer> <item> <part-number warehouse="Warehouse"> E16-25A</part-number> <description>Production-Class</description> <quantity>16</quantity> </item> </order> here is my stylesheet order.xsl <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl: output method="text"/> <xsl:template match="/order/item"> <xsl:value-of select="part-number"/> </xsl:template> </xsl:stylesheet> and i am getting the following output: 2001/1/1/ Company A E16-25A my qestion is why am i getting the date and the customer here?I am expecting to get only the part-number i.e, E16-25A. what am i not understanding here?i would appreciate if anyone could clarify me it. thanks [Code edited by Val] [ August 06, 2002: Message edited by: Valentin Crettaz ]
You get such output because there are default template rules exists in XSLT and you didn't redefine this rules. The default rule for elements is: <xsl:template match="*|/"> <xsl:apply-templates/> </xsl:template> The default rule for text and attributes is: <xsl:template match="text()|@*"> <xsl:value-of select="."/> </xsl:template>
You didn't define rule for root node "/" therefore default rule uses.
Himal, You probably got the point by now ;-) But here is another version that will produce what you want. I would go with Valentin's version, since it's more explicit.
Cheers, Dan
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Originally posted by Sergey Gribok: You get such output because there are default template rules exists in XSLT and you didn't redefine this rules. The default rule for elements is: <xsl:template match="*|/"> <xsl:apply-templates/> </xsl:template> The default rule for text and attributes is: <xsl:template match="text()|@*"> <xsl:value-of select="."/> </xsl:template>
You didn't define rule for root node "/" therefore default rule uses.
Also a little addition to this ...... <xsl:template match="text()|@*"> <xsl:value-of select="."/> </xsl:template> You have to keep in mind that the statement - <xsl:apply-templates /> will not take the recursion to the attributes ( i guess attributes are not treated as nodes) and hence you donot see the text included in the attributes getting printed along with the text() nodes' content; You have to force the thing to happen for attributes (if you really want to) by something like - <xsl:apply-templates select="@*"/> for a given element in context;