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

Another key question

Subject: Another key question
From: "Richard Lander" <rlander@xxxxxxxxxxxxx>
Date: Thu, 17 Oct 2002 11:38:27 -0700
xslt key
 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


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.