xsl-list
[Top] [All Lists]

Re: Preceding-Sibling Axes in Context node.

2004-04-21 09:13:07
Hi Viral,

Please try the XSL.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html" version="1.0"
encoding="UTF-8" indent="yes"/>

<xsl:key name="key-state" match="record"
use="@state"/>

<xsl:template match="/root">
  <html>
    <table>
        <xsl:for-each select="record">
          <xsl:if test="generate-id(.) =
generate-id(key('key-state', @state)[1])">
           <tr>
             <xsl:for-each select="key('key-state', @state)">
               <td>
                 <xsl:value-of select="@city"/>
               </td>
             </xsl:for-each>
           </tr>
          </xsl:if>
        </xsl:for-each>
    </table>
  </html>
</xsl:template>
</xsl:stylesheet>

Regards,
Mukul

 --- "Patel, Viral" <viral(_dot_)patel(_at_)countryfinancial(_dot_)com>
wrote: > 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.



--+------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--
 

________________________________________________________________________
Yahoo! India Matrimony: Find your partner online. 
http://yahoo.shaadi.com/india-matrimony/


<Prev in Thread] Current Thread [Next in Thread>