[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Mike,
You are not getting your attributes in output because the expressions you think should refer to those attributes (e.g. <xsl:value-of select="@ENCODINGANALOG"/>) are not evaluating the way you are expecting. A little study of how XPath expressions are evaluated, in particular the notion of the "context node", would help you a great deal.
When you say
... the context node for the expression "@ENCODINGANALOG" is the C02 node you have selected in the for-each (i.e. the node you are currently processing among the set of C02 elements in the document, //C02). Since no C02 elements have @ENCODINGANALOG attributes, you get none in your output (the node set selected by the value-of instruction is empty).
Try <xsl:value-of select=".//PERSNAME[@ENCODINGANALOG='100$a']@ENCODINGANALOG"/> and you'll get what you want.
But in my experience a beginner's failure to grasp the notion of the context node for XPath often comes in the context of a soft understanding of XSLT's preferred mode of operating, i.e. through templates -- the famous "push" approach to stylesheets vs. the "pull" method which tends to rely much more heavily on xsl:for-each. Your case is certainly one in which a template-based solution would work way better than what you have, since then the context node changes with each template -- meaning you don't have to force it (a strategy which may be exigent, but will soon fail on you in other cases when your data is less regular).
So try:
If you are unclear on why this works, what you need to research is template-based processing, and the concept of the context node for the evaluation of XPaths. Mike Kay's book is excellent; I'm also liking Bob DuCharme's "XSL Quickly" for beginners.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Re: [xsl] Same name Elements in more than one node
Subject: Re: [xsl] Same name Elements in more than one node From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Wed, 26 Dec 2001 12:51:28 -0500 |
Mike,
You are not getting your attributes in output because the expressions you think should refer to those attributes (e.g. <xsl:value-of select="@ENCODINGANALOG"/>) are not evaluating the way you are expecting. A little study of how XPath expressions are evaluated, in particular the notion of the "context node", would help you a great deal.
When you say
<xsl:for-each select="//C02"> <TR> <TD> <FONT size="+3"> <xsl:value-of select=".//PERSNAME[@ENCODINGANALOG='100$a']"/> </FONT> <xsl:text>     : </xsl:text> <xsl:value-of select="@ENCODINGANALOG"/> ...
... the context node for the expression "@ENCODINGANALOG" is the C02 node you have selected in the for-each (i.e. the node you are currently processing among the set of C02 elements in the document, //C02). Since no C02 elements have @ENCODINGANALOG attributes, you get none in your output (the node set selected by the value-of instruction is empty).
Try <xsl:value-of select=".//PERSNAME[@ENCODINGANALOG='100$a']@ENCODINGANALOG"/> and you'll get what you want.
But in my experience a beginner's failure to grasp the notion of the context node for XPath often comes in the context of a soft understanding of XSLT's preferred mode of operating, i.e. through templates -- the famous "push" approach to stylesheets vs. the "pull" method which tends to rely much more heavily on xsl:for-each. Your case is certainly one in which a template-based solution would work way better than what you have, since then the context node changes with each template -- meaning you don't have to force it (a strategy which may be exigent, but will soon fail on you in other cases when your data is less regular).
So try:
<TBODY> <xsl:apply-templates select="//C02"/> <!-- there's probably a better way than to select all C02 components from the root, but for now ... --> </TBODY> ...
<xsl:template match="C02"> <TR> <xsl:apply-templates select=".//PERSNAME[@ENCODINGANALOG='100$a']"/> <xsl:apply-templates select=".//PERSNAME[@ENCODINGANALOG='700$a']"/> </TR> </xsl:template>
<xsl:template match="PERSNAME"> <TD> <FONT size="+3"> <xsl:value-of select="."/> </FONT> <xsl:text>     : </xsl:text> <xsl:value-of select="@ENCODINGANALOG"/> </TD> </xsl:template>
If you are unclear on why this works, what you need to research is template-based processing, and the concept of the context node for the evaluation of XPaths. Mike Kay's book is excellent; I'm also liking Bob DuCharme's "XSL Quickly" for beginners.
Happy holidays! Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Query string syntax, Mike Ferrando | Thread | FW: [xsl] Unique sorting, Andrew Welch |
Re: [xsl] Same name Elements in mor, Mike Ferrando | Date | Re: [xsl] how to assign a xsl varia, Andrew Welch |
Month |