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 February 9th, 2006, 04:41 AM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RazoRmedia
Default differentiating between two nodes

xml as below:

<data>
  <event>
    <market>
      <result>
        ***some more nodes here
      </result>
      <rule4 w_d_time="" overall_deduction="00" runner_deduction="00" runner_number="4" application_code="B" />
      <rule4 w_d_time="" overall_deduction="25" runner_deduction="25" runner_number="4" application_code="A" />
    </market>
   </event>
</data>



now my code is as follows:

<xsl:if test="rule4[@application_code='B'] and rule4[@w_d_time!='']">
  <xsl:text disable-output-escaping="yes">&amp;nbsp; Rule 4 </xsl:text><xsl:value-of select="@w_d_time"/><xsl:value-of select="@overall_deduction"/>
</xsl:if>
<xsl:if test="rule4[@application_code='A']">
  <xsl:text disable-output-escaping="yes">&amp;nbsp; Rule 4 </xsl:text><xsl:value-of select="@overall_deduction"/><xsl:text disable-output-escaping="yes">&amp;nbsp; All Bets</xsl:text>
</xsl:if>



Now the thing is, when I run this, I get the following displayed

Rule 4 &nbsp; All Bets

Any ideas ?

 
Old February 9th, 2006, 04:43 AM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RazoRmedia
Default

(that output is the HTML by the way). The problem is in the fact that it should display the overall reduction.

Its showing neither 00 or 25 so theres two questions really:

1) why is it not displaying? (I have tried rule4[@overall_deduction])
2) how do I differentiate which one I wish to display, ie, the one with the application code of 'A'?

 
Old February 9th, 2006, 05:09 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If your context node is <market>, then it satisfies the second xsl:if condition. But the <market> node doesn't have an attribute called overall_deduction, so nothing is displayed. Every time you write a relative path expression, you need to be aware what the context node is.

And please don't use disable-output-escaping for something as trivial as outputting a NBSP character. You're severely damaging the portability and reusability of your code, and you can produce a NBSP character quite easily with

<xsl:text>#xa0;</xsl:text>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 9th, 2006, 05:27 AM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RazoRmedia
Default

Thanks for your reply Michael,

the contect node is market but using

<xsl:if test="rule4[@application_code='A']">
  <xsl:text>Rule 4</xsl:text>
  <xsl:value-of select="rule4[@overall_deduction]"/>
  <xsl:text> All Bets</xsl:text>
</xsl:if>

still shows nothing. Pardon my ignorance, its bound to be something simple ;)

 
Old February 9th, 2006, 06:25 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This:

<xsl:value-of select="rule4[@overall_deduction]"/>

displays the string-value of the first rule4 element that has an @overall_deduction attribute.

So there are two errors: (a) you want to display the value of the attribute, not the containing element (which has empty content), and (b) you don't want the value of the first rule4 element, you want the one that has @application_code='A' (I assume).

One way to do this is

<xsl:for-each select="rule4[@application_code='A']">
  <xsl:text>Rule 4</xsl:text>
  <xsl:value-of select="@overall_deduction"/>
  <xsl:text> All Bets</xsl:text>
</xsl:for-each>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to value in b/n nodes Swetha XSLT 1 May 20th, 2008 12:20 PM
Merging nodes trishla XSLT 11 October 18th, 2007 03:01 PM
Navigate through nodes abelmirma XML 1 May 7th, 2005 07:32 AM
Exclude Nodes seanhaggerty XSLT 1 February 3rd, 2005 06:00 AM
updating nodes? pafo C# 0 November 11th, 2004 08:22 PM





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