|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Do you know how to refer to a node?
Sorry, I realized later that you were not in the node-and-text
problem camp, but that you wanted to rename the nodes according
to a fixed sequence. Here is a neat way of doing that,
exploiting the fact that document('') refers to the stylesheet
document.
Steve
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="nodes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="customer">
<xsl:copy>
<xsl:for-each select="*">
<xsl:variable name="index" select="position()"/>
<xsl:element name="{document('')//field[$index]}">
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template name="fieldnames">
<field>street</field>
<field>city</field>
<field>state</field>
</xsl:template>
</xsl:stylesheet>
produces:
<?xml version="1.0" encoding="utf-8"?>
<customer><street>1 Main
Street</street><city>Pittsburgh</city><state>PA</state></customer>
from:
<customer>
<node>1 Main Street</node>
<node>Pittsburgh</node>
<node>PA</node>
</customer>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








