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 19th, 2008, 09:17 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default get grandchildrens position()

Hi,

I've been working on this for a few hours, I hope you can help.

I am using XSLT 1.0

Take the following XML:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <manual>
        <gin>
            <ginwp/>
        </gin>
        <sin>
            <sinwp/>
            <sinwp/>
        </sin>
        <fin>
            <finwp/>
        </fin>
    </manual>
</root>
How would I get the position of the following elements in relation to its grandparent <manual>.

<ginwp/>
<sinwp/>
<sinwp/>
<finwp/>


Desired output would be:

1 <ginwp/>
2 <sinwp/>
3 <sinwp/>
4 <finwp/>

I've tried:
<xsl:number level="any" count="child::*" from="/root/manual"/>

But this returns a count of all descendants. e.g. (4567).

Thanks for the help,

Bones



 
Old March 19th, 2008, 09:25 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

The following should work:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="manual">
    <results>
      <xsl:apply-templates select="*/*"/>
    </results>
  </xsl:template>

  <xsl:template match="manual/*/*">
    <xsl:number level="any" count="manual/*/*" from="manual"/>
    <xsl:copy/>
  </xsl:template>

</xsl:stylesheet>
 
Old March 19th, 2008, 09:48 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Sweet. Thanks!







Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the position of an element nazran Javascript How-To 3 February 2nd, 2010 06:56 AM
Position barski XSLT 5 July 11th, 2007 01:54 PM
mouse position angelboy C# 2005 0 April 9th, 2007 04:07 PM
Position: relative; czambran BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 April 7th, 2005 11:22 AM





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