Hello,
I'm trying to do something with keys and having a bit of trouble. In doing so,
I've done some research with some sample data and come up with the following
results. I'm using system.xml.
C:\temp\XSLTProject2->
- type XSLTProject2_data.xml
<test>
<section>
<title>H1</title>
</section>
<section>
<title>H2</title>
</section>
<section>
<title>H2</title>
</section>
<section>
<title>H3</title>
</section>
<section>
<title>H2</title>
</section>
<section>
<title>H1</title>
</section>
<section>
<title>H2</title>
</section>
</test>
C:\temp\XSLTProject2->
- type XSLTProject2.xslt
<?xml version="1.0"?>
<xslt:transform xmlns:xslt="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xslt:key name="sections" match="section" use="generate-id(current())"/>
<xslt:template match="/">
<xslt:apply-templates/>
</xslt:template>
<xslt:template match="test">
<test>
<xslt:apply-templates select="section"/>
</test>
</xslt:template>
<xslt:template match="section">
<xslt:variable name="myID" select="generate-id(.)"/>
<section>
<title><xslt:value-of select="title"/></title>
<para><xslt:value-of select="$myID"/></para>
<para><xslt:value-of select="generate-id(key('sections',
$myID))"/></para>
</section>
</xslt:template>
</xslt:transform>
C:\temp\XSLTProject2->
- type out.xml
<?xml version="1.0" encoding="utf-8" ?>
<test>
<section>
<title>H1</title>
<para>XSLTsection120120120</para>
<para>XSLTsection120120120</para>
</section>
<section>
<title>H2</title>
<para>XSLTsection121120120</para>
<para>XSLTsection120120120</para>
</section>
<section>
<title>H2</title>
<para>XSLTsection122120120</para>
<para>XSLTsection120120120</para>
</section>
<section>
<title>H3</title>
<para>XSLTsection123120120</para>
<para>XSLTsection120120120</para>
</section>
<section>
<title>H2</title>
<para>XSLTsection124120120</para>
<para>XSLTsection120120120</para>
</section>
<section>
<title>H1</title>
<para>XSLTsection125120120</para>
<para>XSLTsection120120120</para>
</section>
<section>
<title>H2</title>
<para>XSLTsection126120120</para>
<para>XSLTsection120120120</para>
</section>
</test>
Is the result above correct? I get the following result out of MSXML4. MSXML3
is mostly the same as this (MSXML4), except that the first section has a string
in the second para that is equal to the string in the first para.
<?xml version="1.0" ?>
<test>
<section>
<title>H1</title>
<para>IDAEAWY</para>
<para></para>
</section>
<section>
<title>H2</title>
<para>IDAGAWY</para>
<para></para>
</section>
<section>
<title>H2</title>
<para>IDAIAWY</para>
<para></para>
</section>
<section>
<title>H3</title>
<para>IDAKAWY</para>
<para></para>
</section>
<section>
<title>H2</title>
<para>IDAMAWY</para>
<para></para>
</section>
<section>
<title>H1</title>
<para>IDAOAWY</para>
<para></para>
</section>
<section>
<title>H2</title>
<para>IDAQAWY</para>
<para></para>
</section>
</test>
What should happen?
My main question, is what does 'current()' mean in the context in which I've
used it within xsl:key.
I'd like to do something like this:
<xslt:key name="sections" match="section"
use="generate-id(preceding-sibling::section[title =
translate(current()/title,'23456789','12345678')][1])"/>
Thanks,
Rich
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list