|
next
|
Subject: Creating dynamically named elements Author: hungry backspace Date: 26 Dec 2007 02:51 PM
|
hello,
i've read a few posts on the subject of creating dynamically-named elements using the name() function. that technique seems to work for me, but only in limited applications. specifically, i'm finding that using it is problematic within certain templates. for example, this template is called within another template, which is in turn called by yet another template:
<xsl:template match="quote">
<xsl:for-each select="*">
<xsl:for-each select="*">
<xsl:variable name="itemName">
<xsl:value-of select="php:function('translateItems', string(name()))" />
</xsl:variable>
<xsl:element name="example">
<xsl:value-of select="$itemName" />
</xsl:element>
<xsl:element name="{$itemName}">
<xsl:value-of select="$itemName" />
</xsl:element>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
the variable assignment to a value that passes through PHP is no problem; i can define that statically and the result is the same, which is this: the next element, <example>, is properly added to the document, and the dynamically generated variable $itemname is properly contained within the element. the element after that, however, causes a runtime error in the XSLT processor, and the only discernible difference to me is that i'm assigning the element name to a variable.
i'm admittedly quite new to XSLT! so there's likely something basic i missed. any advice or comments are greatly appreciated.
thanks very much.
|
|
|