Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 26th, 2009, 08:25 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

The bar '|' is the union operator in XPath so in that example select=". | following-sibling::Parameter[1][some condition]" selects the union of the context node and the first following-sibling Parameter element if it meets the condition. Instead of using one apply-templates with a union of nodes you could also use two apply-templates e.g.
Code:
<xsl:apply-templates select="." mode="m1"/>
<xsl:apply-templates select="following-sibling::Parameter[1][some condition]" mode="m1"'>
current is a function that XSLT defines: http://www.w3.org/TR/xslt#dt-current-node
In my code it is used to compare the 'row' attribute of the following sibling Parameter element to the 'row' attribute of the current Parameter element the template is applied to.

There are three apply-templates in one template, that is true. The first one simply makes sure the current Parameter element content is output with the mode 'm1' template (which contains the code you originally posted yourself). The second apply-templates then makes sure the first following sibling Parameter, if it matches the condition you posted (@col is 2 and the @row is the same as the preceding sibling), is output within the div wrapper element already created. The third apply-templates keeps the sibling recursion alive, ensuring that the first following sibling Parameter which does not have @col as 2 and does not have the same @row is processed.

That is also the reason for the difference you ask about in the fourth question: Inside the wrapper div we want to apply-templates to the first following sibling Parameter element if it matches the condition so we use [1][conditon]. Outside the wrapper div we need to ensure that the first following Parameter element not matching the condition is processed, to keep the sibling recursion alive. So in that case we need [not(condition)][1].
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old November 26th, 2009, 08:31 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Michael,

"1. I've no idea what your js_escapeAmp does or why you need it. Normally you should be using the HTML output method and that should take care of all escaping that's needed."

I have always had problems escaping characters in my xml with xslt.

The js_escapeAmp template just escapes an ampersand.

Could you please elaborate a bit more on this bit of your comment. I get the xml I need from a call to a web service and then use the xslt to transform this xml on the client using javascript. What do you mean by using the HTTP output method? I already use
<xsl:output method="html"/> in my xslt.

"you should be using the HTML output method and that should take care of all escaping that's needed."


Thanks

<xsl:template name="js-escapeAmp">
<xsl:param name="string" />
<xsl:call-template name="substitute">
<xsl:with-param name="string" select="normalize-space($string)" />
<xsl:with-param name="find" select='"%26amp%3B"' />
<xsl:with-param name="replace" select='"&amp;"' />
</xsl:call-template>
</xsl:template>

<xsl:template name="substitute">
<xsl:param name="string" />
<xsl:param name="find" />
<xsl:param name="replace" />
<xsl:choose>
<xsl:when test="$find and $string and contains($string, $find)">
<xsl:value-of select="substring-before($string, $find)" />
<xsl:value-of select="$replace" />
<xsl:call-template name="substitute">
<xsl:with-param name="string" select="substring-after($string,$find)" />
<xsl:with-param name="find" select="$find" />
<xsl:with-param name="replace" select="$replace" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
 
Old November 26th, 2009, 08:39 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Martin,

Wow!! this is quite advanced stuff for me. I will have to read and read your notes to understand the logic

I have one question though. Using your solution what do I have to do to combine the paramenters into one DIV for when the @col = 1 and the @row are the same??

Using my long xslt I just added an OR to the condition like so:

<xsl:template match="Parameter[(@col=2 or @col=1) and @row=following-sibling::Parameter[1]/@row]">

Thanks
 
Old November 26th, 2009, 09:17 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It seems that your js_escapeAmp is actually *unescaping* the ampersand, that is, it is turning the form "%26amp%3B" into a regular ampersand. So the question is, how did it get into that form in the first place? If that's how the web service is sending it, and it's not your web service, then your only options are to complain to the web service provider, or to do what you are doing.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Preceding Franky83 XSLT 1 November 12th, 2007 06:20 PM
Testing equality between nodes..... help!! trinkets XSLT 12 February 27th, 2007 12:27 PM
preceding-sibling jonesyp XSLT 2 November 22nd, 2005 12:29 PM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM
Name Equality and problems with Java cuskichick Pro JSP 0 June 13th, 2005 12:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.