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 January 3rd, 2008, 08:38 PM
Authorized User
 
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing higher level nodes from a template

Hi,

I am currently trying to convert docx bullet or list items into html.

I have noticed that in the xml, all list items that belong to a particular list have the same rsidP.

So in order to start, I have the following xsl that will get me a list of the distinct rsidP's.

<xsl:template name="doLists">

    <xsl:for-each select="distinct-values(/w:document/w:body/w:p/@w:rsidP)" >
            <p>
                    <xsl:value-of select="." /> </p>
    </xsl:for-each>
</xsl:template>

Now, this works in that it displays the list id's; however, I am now stuck in that I am unable to start at the root of the document to filter through these lists.

For instance:

<xsl:template name="doLists">

    <xsl:for-each select="distinct-values(/w:document/w:body/w:p/@w:rsidP)" >
            <xsl:variable name="rsidP" select="." />
            <xsl:for-each select="/w:document/w:body/w:p[rsidP = $rsidP]">
                <p>

                </p>
            </xsl:for-each>
    </xsl:for-each>
</xsl:template>

When I try this I get the error: Not a node item.
This has lead me to believe that I am still stuck and starting from the @w:rsidP element level, and that my xpath is actually trying to do something like
/w:document/w:body/w:p/@w:rsidP/w:document/w:body/w:p[rsidP = $rsidP]

Am I right in thinking this?

So basically, I'm trying to:
1) get a list of the unique ID's
2) for each unique id, iterate thru the nodes (in order) that have the id, and format it (this will need to be recursive as there are nested lists as well)

Can anyone help me out or point me in the right direction?

Cheers,
Mikey
 
Old January 3rd, 2008, 08:57 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you're using distinct-values() then you're using XSLT 2.0

>So basically, I'm trying to:
1) get a list of the unique ID's
2) for each unique id, iterate thru the nodes (in order) that have the id, and format it (this will need to be recursive as there are nested lists as well)

That's basically a description of what xsl:for-each-group does. In XSLT this is usually much easier to use than distinct-values().

<xsl:for-each-group select="/w:document/w:body/w:p" group-by="@w:rsidP">
  <xsl:for-each select="current-group()">
    ...

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 3rd, 2008, 09:06 PM
Authorized User
 
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael.

Is there a way then to iterate through the items of the group?
 
Old January 3rd, 2008, 09:14 PM
Authorized User
 
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, I found that you can iterate through current_group()...
Awesome! Thanks again :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
not able to print child nodes upto 2 level eruditionist XSLT 3 October 30th, 2008 01:10 PM
Accessing nodes contained in a variable geoGregory3 XSLT 2 March 12th, 2008 02:57 PM
*solved* applying same template to multiple nodes Brian Campbell XSLT 3 October 13th, 2006 06:56 PM
Using a recursive template for various nodes spencer.clark XSLT 5 August 2nd, 2005 03:49 PM
Help accessing specific nodes jshl_wiz Javascript 2 June 29th, 2005 09:45 PM





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