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

Re: Preceding-Sibling Axes in Context node.

Subject: Re: Preceding-Sibling Axes in Context node.
From: Mukul Gandhi <mukulgandhi2003@xxxxxxxxxxx>
Date: Wed, 21 Apr 2004 17:13:07 +0100 (BST)
xsl preceding sibling
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.patel@xxxxxxxxxxxxxxxxxxxx>
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.
>  

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

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.