[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Referencing unique values by their order number.


Subject: [xsl] Referencing unique values by their order number.
From: Andreas Kemkes <a5sk4s@xxxxxxxxx>
Date: Fri, 8 Dec 2006 15:00:50 -0800 (PST)

XSLT 1.0 is a constraint.

I'm trying to convert one XML format into another
3rd party one.  The second one requires a set of unique values, which are
referenced by their order number from other parts within the same 3rd party
XML.  I've tried to simplify the real case.

Simplified, the source XML looks
like this:

        <item>V1</item>
        <text>(content)</text>
<text>(content)</text>
        <item>V2</item>
        <text>(content)</text>
<item>V1</item>
        <text>(content)</text>
        <item>V3</item>
<text>(content)</text>
        <text>(content)</text>
        
and it needs to
be transfered into the structures below.
 
The first one, which is just based
on the uniqueness of item values using a test like
item[not(preceding-sibling::item = .)] is easy.
 
I'm using something like
<xsl:template match="item[not(preceding-sibling::item = .)]" mode="items">
<item><xsl:value-of select="."/></item>
        </xsl:template>

to produce
something like:

        <items>
                <item>V1</item> <!-- item 0
-->
                <item>V2</item> <!-- item 1 -->
<item>V3</item> <!-- item 2 -->
        </items>

The second one is where I'm
having problems finding the right expression for the index into the unique
values structure(i.e., the items).

I started with

        <xsl:template
match="text" mode="elements">
                <xsl:variable name="item"
select="preceding-sibling::item[1]"/>
                <element>
<item><xsl:value-of select="'missing-expression'"/></item>
<text><xsl:value-of select="."/></text>
                </element>
</xsl:template>

hoping to be able to construct the item set and use it
together with count() and preceding-sibling, but I can't seem to be able to
find the correct expression for 'missing-expression'.

It needs to have an
output like

        <elements>
                <element>
<item>0</item> <!-- referencing item 0 -->
<text>(content)</text>
                </element>
                <element>
<item>0</item> <!-- referencing item 0 -->
<text>(content)</text>
                </element>
                <element>
<item>1</item> <!-- referencing item 1 -->
<text>(content)</text>
                </element>
                <element>
<item>0</item> <!-- referencing item 0 -->
<text>(content)</text>
                </element>
                <element>
<item>2</item> <!-- referencing item 2 -->
<text>(content)</text>
                </element>
                <element>
<item>2</item> <!-- referencing item 2 -->
<text>(content)</text>
                </element>
        </elements>

Hints
and suggestions regarding techniques are much appreciated.

Thanks,
Andreas
_____________________________________________________________________________
_______
Need a quick answer? Get one in minutes from people who know.
Ask your
question on www.Answers.yahoo.com


Current Thread
Keywords
xml