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 March 22nd, 2007, 05:29 PM
Registered User
 
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with selective counting

Here is a sample of my XML code:

<map>

<topic>

<title>Main Title - I want to count this</title>

<body>...</body>

    <topic>

    <title>Sub title - I don't want to count this</title>

    <body>...</body>

    </topic>

    <topic>

    <title>Sub title - I don't want to count this</title>

    <body>...</body>

    </topic>

</topic>

<topic>

<title>Main Title - I want to count this</title>

<body>...</body>

    <topic>

    <title>Sub title - I don't want to count this</title>

    <body>...</body>

    </topic>

</topic>

</map>

My XSL uses the following code to match against the main titles:

<xsl:template match="*[contains(@class,' topic/topic ')]/*[contains(@class,' topic/title ')]" priority="2">

<xsl:call-template name="get-title"/>

</xsl:template>

The match works fine - only the main titles are picked up and processed differently than the others. But I can't seem to apply the same logic to add numbering - every title is counted, not just the main ones.

Here's what I've tried so far:

1. <xsl:number count="*/*[contains(@class,' topic/topic ')]/*[contains(@class,' topic/title ')]" level="any"/>

2. <xsl:number count="*/*[contains(@class,' topic/title ')]" level="any"/>

3. <xsl:number format="1. " level="any" count="topic|title"/>

Is there a way I could add a condition so that only the titles of topics who are direct descendants of map are counted, not the titles of topics who are descendants of other topics?


 
Old March 22nd, 2007, 06:27 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I can't really follow your logic. You seem to be numbering elements based on the presence of an @class attribute, but in your XML source none of the elements has a @class attribute.

If it's true that

 match="*[contains(@class,' topic/topic ')]/*[contains(@class,' topic/title ')]"

matches all the elements you want to number, and only the ones you want to number, then you should be able to use

<xsl:number count=" match="*[contains(@class,' topic/topic ')]/*[contains(@class,' topic/title ')]" level="any"/>

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
selective validation Country/State dsmportal ASP.NET 2.0 Professional 3 August 9th, 2006 04:01 PM
selective validation Country/State dsmportal ASP.NET 1.0 and 1.1 Professional 0 August 3rd, 2006 12:35 PM
UPDATE query throws error in selective MSI tables eelisMX General .NET 0 July 14th, 2005 06:29 AM
Help required Selective Printing Access Reports Jim Bendfeldt Access 2 August 27th, 2003 10:27 PM





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