Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 January 3rd, 2008, 08:38 PM
Authorized User
 
Join Date: Jan 2007
Location: sydney, nsw, Australia.
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
Reply With Quote
  #2 (permalink)  
Old January 3rd, 2008, 08:57 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 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
Reply With Quote
  #3 (permalink)  
Old January 3rd, 2008, 09:06 PM
Authorized User
 
Join Date: Jan 2007
Location: sydney, nsw, Australia.
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?
Reply With Quote
  #4 (permalink)  
Old January 3rd, 2008, 09:14 PM
Authorized User
 
Join Date: Jan 2007
Location: sydney, nsw, Australia.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, I found that you can iterate through current_group()...
Awesome! Thanks again :)
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
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



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


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