Paul,
+ <xsl:for-each select="/rpm-info/copyright"> + <xsl:element name="copyright"> + <xsl:for-each select="/rpm-info/copyright/year"><xsl:element name="year"> + <xsl:value-of select="node()"/> + </xsl:element></xsl:for-each> + <xsl:for-each select="/rpm-info/copyright/holder"> + <xsl:element name="holder"> + <xsl:value-of select="node()"/> + </xsl:element> + </xsl:for-each> + </xsl:element> + </xsl:for-each>
This is a bit verbose. Embedding so much of each element's path here can be detrimental to maintainability. The xsl:for-each cycles through the available /rpm-info/copyright/ elements, setting the symbol "." or node() to the element currently getting the "focus", so you could write this as:
<xsl:for-each select="/rpm-info/copyright"> <xsl:element name="copyright"> <xsl:for-each select="year"> <xsl:value-of select="."/> </xsl:for-each> </xsl:element> </xsl:for-each>
HTH.
On Mon, 2006-01-02 at 15:27 -0600, Tommy Reynolds wrote:
Paul,
<xsl:for-each select="/rpm-info/copyright">
- <xsl:element name="copyright">
<xsl:for-each select="/rpm-info/copyright/year"><xsl:element name="year">
<xsl:value-of select="node()"/>
</xsl:element></xsl:for-each>
<xsl:for-each select="/rpm-info/copyright/holder">
<xsl:element name="holder">
<xsl:value-of select="node()"/>
</xsl:element>
</xsl:for-each>
- </xsl:element>
</xsl:for-each>
This is a bit verbose. Embedding so much of each element's path here can be detrimental to maintainability. The xsl:for-each cycles through the available /rpm-info/copyright/ elements, setting the symbol "." or node() to the element currently getting the "focus", so you could write this as:
<xsl:for-each select="/rpm-info/copyright"> <xsl:element name="copyright"> <xsl:for-each select="year"> <xsl:value-of select="."/> </xsl:for-each> </xsl:element> </xsl:for-each>
HTH.
Actually, I thought the same thing before my commit, WRT the absolute element path, then promptly forgot to go back and change it. Thanks for catching this. The node() thing I didn't realize was an issue. Are there any usage differences between "node()" and "."?
Paul W. Frields wrote:
Actually, I thought the same thing before my commit, WRT the absolute element path, then promptly forgot to go back and change it. Thanks for catching this. The node() thing I didn't realize was an issue. Are there any usage differences between "node()" and "."?
As I understand XPath: "node()" is a node test that yields true for any type of node whether it be an attribute, element, et cetera. The "." is short for self::node() and always refers to the node currently being pointed to, the context node. node() can refer to nodes other than the context node, as in "child::node()" (all nodes that are immediate children of the context node) or "ancestor::node()" (all nodes that are parents, grandparents, etc. of the context node).
On Mon, 2006-01-02 at 21:06 -0500, Chris Lennert wrote:
Paul W. Frields wrote:
Actually, I thought the same thing before my commit, WRT the absolute element path, then promptly forgot to go back and change it. Thanks for catching this. The node() thing I didn't realize was an issue. Are there any usage differences between "node()" and "."?
As I understand XPath: "node()" is a node test that yields true for any type of node whether it be an attribute, element, et cetera. The "." is short for self::node() and always refers to the node currently being pointed to, the context node. node() can refer to nodes other than the context node, as in "child::node()" (all nodes that are immediate children of the context node) or "ancestor::node()" (all nodes that are parents, grandparents, etc. of the context node).
I understand that node() is a function that can be applied to nodes other than the current context. I should have been more clear in my question; what I meant was, in a given context are:
<xsl:value-of select="node()"/>
and:
<xsl:value-of select="."/>
always equivalent?