Hi,
I have a question about preceding-sibling. I have following XML
<root>
<record id="1" city="Carbondale" state="IL"/>
<record id="2" city="Columbia" state="MO"/>
<record id="3" city="Bloomington" state="IL"/>
<record id="4" city="St. Louis" state="MO"/>
<record id="5" city="Chicago" state="IL"/>
</root>
And I have following XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<table>
<xsl:apply-templates match="//root/record">
<xsl:sort select="@state"/>
<xsl:sort select="@city"/>
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="record">
<xsl:if test="not ( (preceding-sibling::*/@state) = @state )">
<!-- Some logic that will print out the create a new table
row (tr) and print out the state name....-->
</xsl:if>
<td><xsl:value-of select="@city"/></td>
</xsl:template>
</xsl:stylesheet>
What I want is an output where it would to create one table row per state
and list all of its city in the same row but a different <td>. In my root
template I am sorting the document by state when I do apply templates. In
the "record" template, I do when I do "preceding-sibling::*/@state" it would
bring me back the state attribute of the preceding sibling in the acutal xml
document and not in the current context.
So for example if I just did apply-templates sorted by state and city, xsl
should process my nodes in the order below and I have also printed out the
"preceding-sibling" value that my xsl is giving me for each node and the
"preceding-sibling" value that I would expect.:
IL, Bloomington
-XSL's preceding-sibling: MO, Columbia
-Preceding-Sibling value that I would like: none
IL, Carbondale
-XSL's preceding-sibling: none
-Preceding-Sibling value that I would like: IL, Bloomington
IL, Chicago
-XSL's preceding-sibling: MO, St. Louis
-Preceding-Sibling value that I would like: IL, Carbondale
MO, Columbia
-XSL's preceding-sibling: IL, Carbondale
-Preceding-Sibling value that I would like: IL, Chicago
MO, St. Louis
-XSL's preceding-sibling: IL, Bloomington
-Preceding-Sibling value that I would like: MO, Columbia
What would I need to do to achieve the preceding-sibling value that I want?
Is it even possible? I already tried using <xsl:key> but that didnt work
either. If you want me to explain my question then let me know.
Any help would be appreciated.
Thanks,
V Patel.