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 15th, 2003, 06:15 AM
Registered User
 
Join Date: Aug 2003
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
 
Old August 15th, 2003, 06:36 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old August 15th, 2003, 09:04 AM
Registered User
 
Join Date: Aug 2003
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

 
Old August 16th, 2003, 01:54 AM
Friend of Wrox
 
Join Date: Jun 2003
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





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





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