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 August 20th, 2010, 10:01 AM
Authorized User
 
Join Date: Aug 2010
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default Matching templates causing problem

My xml code(example)
Code:
<orderprice>
  <orderstack>
    <order>
      <ord1>
        120
      </ord1>
      <ord2>
        130
      </ord2>
    </order>
  </orderstack>
  <orderamt>
    <order>
      <ordprice1>
        440
      </ordprice1>
      <ordprice2>
        450
      </ordprice2>
    </order>
  </orderamt>
</orderprice>
I have 2 templates as below.


Code:
<xsl:template match ="order/*">
 <!--something--!>
</xsl:template>

<xsl:template match ="ordprice1">
<!-- different rules than first template--!>
</xsl:template>

The problem is that when I use
<xsl:apply-templates select="order/*" />
it never invokes the 2nd template. Since the contents of order can keep changing, I need to use "order/*". How can I invoke 2nd template.
 
Old August 20th, 2010, 10:13 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Simply apply the attribute priority="2" to the second template, so when it matches an element it has a greater priority than the other template.

The default priority is actually 0.5 I believe, so any number > 0.5 will work.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
pushkar_joshi (August 20th, 2010)
 
Old August 20th, 2010, 10:22 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Further information: The rules for conflict resolution are a bit complicated, and are given here in the spec: http://www.w3.org/TR/xslt#conflict

Basically, "order/*" is more specific (and hence higher priority) than "orderprice1". "order/orderprice1" would be the same priority as "order/*" and should report an error (or if not then choose the last template in the stylesheet).

Giving the second template a high manual priority is the quickest way to make sure the correct template runs if it matches.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 20th, 2010, 10:31 AM
Authorized User
 
Join Date: Aug 2010
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default Re:

It did not give me error but chose the last template. Assigning priority worked. Thanks for the link and info.





Similar Threads
Thread Thread Starter Forum Replies Last Post
<apply-template select> causing problem pushkar_joshi XSLT 6 August 18th, 2010 03:29 AM
Problem in Matching XML Derived Types whelanj XSLT 4 December 9th, 2009 06:55 PM
apply-templates problem within for-each loop mister_mister XSLT 2 January 22nd, 2007 05:40 PM
BLOB used to store image in 9i is causing problem asiff Oracle 0 October 8th, 2004 02:51 AM
problems with xpath and matching templates Gero Meißner XSLT 3 August 16th, 2003 01:54 AM





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