This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Problem with key()


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]