This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Problem with key()
- To: xsl-list <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] Problem with key()
- From: Kevin Burges <xmldude at burieddreams dot com>
- Date: Fri, 25 May 2001 12:56:36 +0100
- Organization: burieddreams.com
- Reply-To: xsl-list at lists dot mulberrytech dot com
I'm trying to use keys from an external document, and having problems. Here's the relevant XSLT:
<!-- define a key of lengths, only including instances where the length is specified -->
<xsl:key name="fieldlength" match="/file/group/field/@length[@length]" use="@name"/>
<xsl:template match="field">
<!-- keep a note of current location -->
<xsl:variable name="currentlocation" select="."/>
<!-- change context to the external document -->
<xsl:for-each select="document('datastructure.xml')">
<xsl:variable name="length"><xsl:value-of select="key(fieldlength, $currentlocation/@name)"/></xsl:variable>
<!-- other stuff in here -->
</xsl:for-each>
</xsl:template>
When processing, I am given an error saying:
"An empty string '' is not a valid name"
If I comment out the bit that sets the @length variable, it works fine, so presumably this is what's causing the problem.
The format of the external file is:
<datastructure>
<file>
<group>
<field name="a0" length="2"/> (@name mandatory, @length optional)
</group>
</file>
</datastructure>
The format of the <field> element in the document being processed is:
<field name="a0"/> (@name mandatory)
What is causing this not to work?
--
May the flares be with you,
Kevin mailto:xmldude@burieddreams.com
++++++++++++ Cool music - http://mp3.com/marshan
++++++ Attitude Webzine - http://burieddreams.com/attitude
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list