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

RE: Template call question

Subject: RE: Template call question
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Mon, 28 Jun 2004 16:59:53 +0100
xsl node set call
I haven't fully understood this, but I've made a few points where the code
looks questionable. 

> I have the following xslt:
> 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:output method="xml" version="1.0" encoding="UTF-8"
> indent="yes"/>
> 
> <xsl:variable name="MYPARENT" 
> select="Redirect_URL_Comparison/QUERY1"/>
> <xsl:template match="Redirect_URL_Comparison">
> 
> <table>
> <xsl:variable name="ORG_URL"
> select="QUERY1/row/VWCAMPAIGNREDIRECT.AR_URL"/>

The QUERY1 has multiple rows, so this will select a set of elements. No
problem with that, but because you used a singular variable name I'm not
sure you're aware of it.

> <xsl:variable name="NEW_URL" select="NONE"/>

Since you have no elements named "NONE", this variable will be an empty
node-set. Again, not intrisically wrong, so long as you know what you are
doing.

> <tr>
> 		<td>name:</td>
> 		<td>
> 			<xsl:value-of
> select="$MYPARENT/row/VWCAMPAIGNREDIRECT.AR_NAME"/>

Because there are multiple rows, xsl:value-of (in XSLT 1.0) will output the
value of this item in the first row. Is that what you intended?

> <xsl:for-each select="QUERY1">

There is only one QUERY1 element in your data, so sorting the set of QUERY1
elements is not going to achieve much.
> 
> <xsl:sort select="row/VWCAMPAIGNREDIRECT.AR_URL"/>
> 
> <xsl:call-template name="get_url">
> <xsl:with-param name="PREV_URL"/>
> <xsl:with-param name="CURR_URL" select="$ORG_URL"/>
> </xsl:call-template>
> </xsl:for-each>
> </table>
> 
> </xsl:template>
> 
> 
> <xsl:template name="get_url">
>  <xsl:param name="PREV_URL"/>
>  <xsl:param name="CURR_URL"/>
> 
> <xsl:for-each
> select="$MYPARENT/row[VWCAMPAIGNREDIRECT.AR_URL=$CURR_URL]">

In the xsl:for-each you're processing all the rows where this item is equal
to $CURR_URL, which as noted earlier is actually a node-set containing all
the values of VWCAMPAIGNREDIRECT.AR_URL. "=" returns true if the value
matches any of these values, which it always will, because all the values
are present in the set.  

> <tr>
> <xsl:choose>
> <xsl:when
>
test="((normalize-space($CURR_URL)=normalize-space(VWCAMPAIGNREDIRECT.AR_URL
)) )">

Now you have me completely confused: you've selected nodes where A=$B, and
now you're testing to see if normalize-space(A)=normalize-space($B). If two
strings are equal, they will still be equal after normalizing whitespace, so
the xsl:when branch will always be chosen. In fact it's more subtle than
this, because normalize-space selects the first node in the node-set, but I
think we're now so many errors deep that it's not worth further analysis.

Michael Kay


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.