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

RE: XPath Query

Subject: RE: XPath Query
From: Rene de Vries <RdVries@xxxxxxxxxxx>
Date: Mon, 16 Jul 2001 11:04:37 +0200
xpath query table
Hi Bryan,

Think in templates!!!! xsl:call-template is only used for universal functions which you want to use at several places.

	<xsl:template match="DATA">
		<table border="1">
			<xsl:apply-templates select="HISTORY"/>
		</table>
	</xsl:template>
	
	<xsl:template match="HISTORY">
		<xsl:variable name="NameCode" select="NAME"/>
		
		<tr>
			<td>
				<xsl:value-of select="DESCRIPTION"/>
			</td>
			<td>
				<xsl:value-of select="//DATA/NAME[@CODE=$NameCode]"/>
			</td>
		</tr>
	</xsl:template>

Greetings Rene
   { @   @ }
        ^
      \__/

"You don't need eyes to see, you need vision!"

-----Oorspronkelijk bericht-----
Van:	Bryan Tulloch [SMTP:b.tulloch@xxxxxxxxxxxxx]
Verzonden:	maandag 16 juli 2001 10:45
Aan:	'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
Onderwerp:	 XPath Query


Hi,

I have tried to get the following to work, but thus far have only been able
to get part of the output I need.

My XML:

<DATA>
	<HISTORY>
		<NAME>21</NAME>
		<DESCRIPTION>This is a history item 1</DESCRIPTION>
	</HISTORY>
	<HISTORY>
		<NAME>22</NAME>
		<DESCRIPTION>This is a history item 2</DESCRIPTION>
	</HISTORY>
	<HISTORY>
		<NAME>21</NAME>
		<DESCRIPTION>This is a history item 3</DESCRIPTION>
	</HISTORY>
	<HISTORY>
		<NAME>24</NAME>
		<DESCRIPTION>This is a history item 4</DESCRIPTION>
	</HISTORY>
	<HISTORY>
		<NAME>21</NAME>
		<DESCRIPTION>This is a history item 5</DESCRIPTION>
	</HISTORY>

	<NAME CODE="21">
		<PERSON>Fred Bloggs</PERSON>
	</NAME>
	<NAME CODE="22">
		<PERSON>John Smith</PERSON>
	</NAME>
	<NAME CODE="24">
		<PERSON>Fred Jones</PERSON>
	</NAME>
</DATA>


My desired output:

<TABLE>
<TR><TD>This is a history item 1</TD><TD>Fred Bloggs</TD></TR>
<TR><TD>This is a history item 2</TD><TD>John Smith</TD></TR>
<TR><TD>This is a history item 3</TD><TD>Fred Bloggs</TD></TR>
<TR><TD>This is a history item 4</TD><TD>Fred Jones</TD></TR>
<TR><TD>This is a history item 5</TD><TD>Fred Bloggs</TD></TR>
</TABLE>


My XSL (below) displays the description in the first column of the table.
However, I have not been able to find the correct XPath expression to put
the data needed for the second column into the table. I imagine that I need
to call another template such as "third" below, but don't know what to put
in it. By the way, I have spent several hours trying to solve this one, so
I'm not just being lazy!

<?xml version="1.0" encoding="utf-8"?>

<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="items"
select="//DATA[HISTORY/NAME=NAME/@CODE]/HISTORY/NAME" />

<xsl:template match="/">
<TABLE>
<xsl:call-template name="second" />
</TABLE>
</xsl:template>

<xsl:template name="second">
<xsl:for-each select="//DATA[./NAME/@CODE=$items]/HISTORY">
<TR>
<TD>
<xsl:value-of select="DESCRIPTION" />
</TD>
</TR>
</xsl:for-each>
<xsl:call-template name="third" />
</xsl:template>

<xsl:template name="third">
</xsl:template>

</xsl:transform>


Bryan

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 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.