|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Newbie problem: namespace breaks key
Is there a reason why <xsl:key> would break when a namespace is added
to the source document?
Example: I begin with this input xml:
----
<?xml version="1.0" encoding="UTF-8"?>
<FMPDSORESULT>
<ROW rowid='1'>
<ITEM type="main">Krazy Kat</ITEM>
<ITEM type="other">Ignatz</ITEM>
<ITEM type="other">Offisa Pup</ITEM>
</ROW>
<ROW rowid='2'>
<ITEM type="main">Superman</ITEM>
<ITEM type="other">Lex Luther</ITEM>
<ITEM type="other">Lois Lane</ITEM>
</ROW>
</FMPDSORESULT>
----Then apply this transformation: ---- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:key name="item_match" match="ITEM" use="@type"/> <xsl:template match="ROW"> <xsl:variable name="thisRow" select="@rowid"/> <mainCharacter> <xsl:value-of select="key('item_match', 'main')[position()= $thisRow]"/> </mainCharacter> </xsl:template> <xsl:template match="text()"/> <xsl:template match="/">
<strips>
<xsl:apply-templates select="FMPDSORESULT"/>
</strips>
</xsl:template>
</xsl:stylesheet>
----I get the following output: ---- <?xml version="1.0" encoding="utf-8"?> <strips> <mainCharacter>Krazy Kat</mainCharacter> <mainCharacter>Superman</mainCharacter> </strips> ---- All well and good. Now, I add a namespace to the input XML, so that the first two lines read: ---- <?xml version="1.0" encoding="UTF-8"?> <FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult"> ---- ...and I make the appropriate changes in my XSLT, adding the prefixes where I reference an element, so that my transformation now looks like this: ---- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:fm="http://filemaker.com/fmpdsoresult" exclude- result-prefixes="fm"> <xsl:output method="xml" indent="yes"/> <xsl:key name="item_match" match="fm:ITEM" use="@type"/> <xsl:template match="fm:ROW"> <xsl:variable name="thisRow" select="@rowid"/> <mainCharacter> <xsl:value-of select="key('item_match', 'main')[position()= $thisRow]"/> </mainCharacter> </xsl:template> <xsl:template match="text()"/> <xsl:template match="/"> <strips> <xsl:apply-templates select="fm:FMPDSORESULT"/> </strips> </xsl:template> </xsl:stylesheet> ---- my result XML comes out empty. The problem seems to be that the <key> function results in an empty node set after the namespace prefixes are added. Is this due to some newbie mistake on my part, like not adding the prefix in some place where I should have? Or does <xsl:key> have a problem with namespaces? Thanks-- Robert Carter (Oxygen 8.2, XSL 1.0, Saxon 6.5.5)
|
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








