ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
[xsl] MSXML4, key() across node-set
by Alex Schuetz other posts by this author
Dec 20 2001 8:16PM messages near this date
[xsl] even and odds | Re: [xsl] MSXML4, key() across node-set
As far as I can tell, when using a key() with the MSXML4 extention
node-set(),
the call to key('key-name', val)[1] does not always return the same node for
a constant val.

I have this stylesheet:

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"> 

<xsl:variable name="set"
select="msxsl:node-set(document(/files/node/@path))"/> 
<xsl:key name="k-id" match="person" use="@id" /> 

<xsl:template name="distinct"> 
        <xsl:for-each select="$set/doc/person[@id='4']"> 
            <info self-id="{generate-id(.)}"
index-id="{generate-id(key('k-id',@id)[1])}"> 
                <self> 
                    <xsl:copy-of select="."/> 
                </self> 
                <index> 
                    <xsl:copy-of select="key('k-id',@id)[1]" /> 
                </index> 
            </info> 
        </xsl:for-each> 
</xsl:template> 

<xsl:template match="/"> 
<test> 
<xsl:call-template name="distinct" /> 
</test> 
</xsl:template> 
</xsl:stylesheet> 

And two input files:

-------------------------------------------
input1.xml
<?xml version="1.0" encoding="utf-8" ?> 
 <doc> 
        <person name="onePerson" id="4" /> 
</doc> 
-------------------------------------------
input2.xml
<?xml version="1.0" encoding="utf-8" ?> 
 <doc> 
        <person name="otherPerson" id="4" /> 
</doc> 
-----------------------------------------------
When I run my stilesheet I get:

 <?xml version="1.0" encoding="UTF-16" ?> 
- <test xmlns:msxsl="urn:schemas-microsoft-com:xslt"> 
- <info self-id="IDAUQ2N" index-id="IDAUQ2N"> 
-     <self> 
          <person name="onePerson" id="4" /> 
      </self> 
-     <index> 
          <person name="onePerson" id="4" /> 
      </index> 
      </info> 
-         <info self-id="IDAIY2N" index-id="IDAIY2N"> 
-     <self> 
          <person name="otherPerson" id="4" /> 
      </self> 
-     <index> 
          <person name="otherPerson" id="4" /> 
      </index> 
      </info> 
  </test> 

It looks like there is a seperate key for each tree-fragment in the
node-set.
Did I miss something, or is this a known problem?

-alex




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
Thread:
Alex Schuetz
Joerg Heinicke

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved