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

banging my head against the wall (key, actually)

Subject: banging my head against the wall (key, actually)
From: "Syd Bauman s.bauman@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 24 Apr 2015 01:30:26 -0000
 banging my head against the wall (key
I fully expected method 1 and method 2 in the following stylesheet
(which reads itself as input) to produce the same result.

Method 1 is to access nodes from a key all at once by handing key()
a single sequence of four key-values.

Method 2 is to access nodes from a key one at a time by handing key()
a single key-value four times.

Obviously I'm missing something, but I'll be darned if I can figure
out what. I have, of course, tried a bunch of variations (like using
"(string())" instead of "string(.)" as the 2nd arg to 2nd key()), but
to no avail. Any thoughts?

Note that the @alpha bit is, at the moment, entirely unused.

XSLT and input
---- --- -----
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
  exclude-result-prefixes="xs xd"
  version="2.0">
  
  <xd:doc scope="stylesheet">
    <xd:desc>
      <xd:p n="1">one</xd:p>
      <xd:p n="2">two dos</xd:p>
      <xd:p n="3">three tres III</xd:p>
      <xd:p n="4">f o u r</xd:p>
    </xd:desc>
  </xd:doc>
  
  <xsl:output method="text"/>
  <xsl:key name="tst" match="xd:desc/xd:p" use="."/>
  
  <xsl:template match="/">
    <xsl:variable name="set">
      <xsl:apply-templates select="//xd:p"/>
    </xsl:variable>
    <!-- method 1: -->
    <xsl:for-each select="key('tst', $set/duck/string(.) )">
      <xsl:message>debug1: <xsl:value-of select="@n"/></xsl:message>
    </xsl:for-each>
    <!-- method 2: -->
    <xsl:for-each select="$set/duck">
      <xsl:message>debug2: <xsl:value-of select="key('tst', string(.) )/@n"/></xsl:message>
    </xsl:for-each>
  </xsl:template>
  
  <xsl:template match="xd:p">
    <duck alpha="{substring('abcd',xs:integer(@n),1)}"><xsl:value-of select="."/></duck>
  </xsl:template>
  
</xsl:stylesheet>

expected output
-------- ------
debug1: 1
debug1: 2
debug1: 3
debug1: 4
debug2: 1
debug2: 2
debug2: 3
debug2: 4

actual output
------ ------
debug1: 1
debug1: 2
debug1: 3
debug1: 4
debug2: 
debug2: 
debug2: 
debug2: 

processor
---------
"Saxon-HE 9.5.1.3J from Saxonica" running in "GNU bash, version
4.2.25(1)-release" on an Ubuntu system (12.04, I think).[1]

Notes
-----
[1] Linux albus 3.5.0-18-generic #29-Ubuntu SMP Thu Oct 25 07:26:14
    UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

-- 
 Syd Bauman, EMT-Paramedic
 Senior XML Programmer/Analyst
 Northeastern University Women Writers Project
 s.bauman@xxxxxxx or
 Syd_Bauman@xxxxxxxxxxxxxxxx

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-2013 All Rights Reserved.