Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 15th, 2003, 06:15 AM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default problems with xpath and matching templates

THE TEMPLATES:

<xsl:template match="article">
<xsl:apply-templates select="title"/>
</xsl:template>

<xsl:template match="article[position()=1]">
<xsl:apply-templates select="title"/>
</xsl:template>

<xsl:template match="article[position()=1]/title">
<xsl:text>Title#1</xsl:text>
</xsl:template>

<xsl:template match="article[position()>1]/title">
<xsl:text>Title#x</xsl:text>
</xsl:template>


THE DOCUMENT:
<document>
<article><title>Title#1</title></article>
<article><title>Title#2</title></article>
</document>

THE PROBLEM:
The template for 'title' for the first(!) 'article' doesn't match. I use libxslt 10032.
Can anyone tell me whether the templates are wrong or if there is a bug in libxslt?

Thank you very much!
Gero
Reply With Quote
  #2 (permalink)  
Old August 15th, 2003, 06:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Nor Hachin, Kotayk, Armenia.
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

The templates you supplied have a drawback: check the "match" attribute for the 3-rd and 4-th templates; the quotation mark(") is missing. Try to correct this and then test the code, it should do what you intended.

Regards,
Armen
Reply With Quote
  #3 (permalink)  
Old August 15th, 2003, 09:04 AM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry!!! I added the quotation marks. The original templates contain the quotation marks and caused the problem I described. So the problem is not a syntax error.

Regards,
Gero

Reply With Quote
  #4 (permalink)  
Old August 16th, 2003, 01:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Nor Hachin, Kotayk, Armenia.
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Ok. I tried to test the code with Saxon 6.5.2 with the following stuff:

XML source document:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<document>
    <article>
        <title>Title#1</title>
    </article>
    <article>
        <title>Title#2</title>
    </article>
    <article>
        <title>Title#3</title>
    </article>
</document>
XSL stylesheet:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="article">
      <xsl:apply-templates select="title"/>
    </xsl:template>

    <xsl:template match="article[position()=1]">
      <xsl:apply-templates select="title"/>
    </xsl:template>

    <xsl:template match="article[position()=1]/title">
      <xsl:text>Title#1</xsl:text>
    </xsl:template>

    <xsl:template match="article[position()>1]/title">
      <xsl:text>Title#x</xsl:text>
    </xsl:template>
</xsl:stylesheet>
and got the following output:

Code:
    Title#1
    Title#x
    Title#x
That is, it's working fine.

Try to test exactly the same code with the same source doc. It's interesting: what will be the output with libxslt 10032? May be you need to add a template rule for the document root(/)? Although built-in template is applied when it's not there, but in any case try to put also the template rule for document root.

Regards,
Armen
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Maps And Templates problems dude81 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 March 10th, 2007 01:44 AM
Sum function and XPath problems tslag XSLT 2 June 26th, 2006 10:23 AM
Doubt in XPATH synax in <xsl:apply-templates > rajatake XSLT 3 May 4th, 2006 06:30 AM
Problems passing XPATH as a paramater to for-all bmart22 XSLT 3 January 19th, 2006 03:40 PM
XPath matching with a default namespace rich_unger XSLT 5 December 4th, 2003 01:22 AM



All times are GMT -4. The time now is 03:12 AM.


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