[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Newbie problem: namespace breaks key

Subject: Newbie problem: namespace breaks key
From: Robert Carter <rcarter0@xxxxxxxxxxxxx>
Date: Sat, 17 Nov 2007 18:10:21 -0600
 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)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.