This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
empty element sabotages xsl:key
- To: xsl-list at lists dot mulberrytech dot com
- Subject: [xsl] empty element sabotages xsl:key
- From: "Nick Ridout" <costempd at us dot ibm dot com>
- Date: Tue, 13 Feb 2001 17:26:35 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
Just wondered if anyone could explain this? I was getting results with key
() that I couldn't understand, and after much hair-pulling decided to ask
here. I deleted a bunch of lines from my input XML so it would be short
enough to post, and all of a sudden key() started working. So I played
with it until I found an element that, when present, appeared to sabotage
<xsl:key>. Is it illegal for an attribute to be set to null?
<OUTSYSNUMBER CODE=""></OUTSYSNUMBER>
I admit to being backleveled. I think I'm running Xerces 1.0.3 (Xalan.jar
and Xerces.jar that came with LotusXSL 1.0.1).
Thanks,
Nick Ridout
ps: I hope it's ok to jump in with this question, as I haven't followed
this list in a while. I did look at DaveP's FAQ (very helpful) and made an
attempt to find something in the archives, but if this has come up before I
missed it.
===========================================
Here's the input XML (including the offending element):
<?xml version="1.0" ?>
<PRCDATA>
<CONTRACTDATA>
<COUNTRY CODE="649">649</COUNTRY>
<AREA>R11</AREA>
<OUTSYSNUMBER CODE=""></OUTSYSNUMBER>
</CONTRACTDATA>
<LINEITEM TYPE="SL">
<SOURCE>GPE</SOURCE>
<BCC>3L10</BCC>
</LINEITEM>
<LINEITEM TYPE="SL">
<SOURCE>GPE</SOURCE>
</LINEITEM>
</PRCDATA>
=======================================
Here's the XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl
="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="type" match="LINEITEM" use="@TYPE"/>
<xsl:template match="/">
<xsl:apply-templates select="PRCDATA"/>
</xsl:template>
<xsl:template match="PRCDATA">
<xsl:element name="root">
<lineitems-by-key>
<xsl:apply-templates select="key('type','SL')"/>
</lineitems-by-key>
<lineitems-by-pattern>
<xsl:apply-templates select="LINEITEM[@TYPE='SL']"/>
</lineitems-by-pattern>
</xsl:element>
</xsl:template>
<xsl:template match="LINEITEM">
<Type><xsl:value-of select="@TYPE"/></Type>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
=======================================
Here's the output when the offending element is included:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<lineitems-by-key/>
<lineitems-by-pattern>
<Type>SL</Type>
<Type>SL</Type>
</lineitems-by-pattern>
</root>
========================================
Here's the output when I remove the offending element:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<lineitems-by-key>
<Type>SL</Type>
<Type>SL</Type>
</lineitems-by-key>
<lineitems-by-pattern>
<Type>SL</Type>
<Type>SL</Type>
</lineitems-by-pattern>
</root>
==== END OF POST ===========================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list