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 4th, 2008, 08:00 PM
Authorized User
 
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Modify XSLT

Hi,

I am currently working on part of an XSLT that handles lists (bullet and numbered) in word docx documents (WordML).

I have made my xslt to do it, however, I think that the way that I did it, doesnt do it in place. Instead, it finds the items, and processes them all.

i.e.

<xsl:template name="doLists" >


    <xsl:for-each-group select="*" group-by="@w:rsidP" >

                <xsl:call-template name="processItem">
                        <xsl:with-param name="lvl" select="number(w:pPr/w:numPr/w:ilvl/@w:val)-1"/>
                        <xsl:with-param name="pos" select="0"/>
                    </xsl:call-template>
    </xsl:for-each-group>

</xsl:template>

How do I change it to keep it in place? i.e. as it is applying the templates, if it comes across one group of rsidP's (ideally i'll need to change this so that the rsidP exists and that a decendant element contains the value "ListParagraph") it processes them in place.

oh and the main part of my xslt just calls doLists.

i.e.

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"
 xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">

<xsl:template match="w:document/w:body">

<html>
    <head>
        <title></title>
    </head>
    <body>

        <xsl:call-template name="doLists" />

    </body>
</html>

</xsl:template>

Mikey
 
Old January 4th, 2008, 09:18 PM
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

This is because you are asking it to group with:

    <xsl:for-each-group select="*" group-by="@w:rsidP" >

Also please provide some raw xml (not the whole file) and some one can better help you.

Thx


 
Old January 5th, 2008, 07:22 PM
Authorized User
 
Join Date: Jan 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Below is a sample of the xml (its part of a word document bullet list).

it has a document node, then a body node, and then several paragraph (w:p) nodes.

Inside each paragpraph, if the paragraph is a special paragraph, it has an extra element of the rsidP, and then also, it has w:pPr/w:pStyle/@w:val of "ListParagraph" if it is a list item.

I guess I could group it initially by ListParagraph and then group it by numId which is the Id number of each list, instead of the rsidP. I'll still have the problem of getting it in place though.


<w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
  <w:body>
    <w:p w:rsidR="00B75C70" w:rsidRDefault="00B75C70">
      <w:r>
        <w:t>This is some text that does not belong into a list.</w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="00B75C70" w:rsidRDefault="00B75C70">
      <w:r>
        <w:t>The below list is a small list of Mammals and Reptiles</w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="0092103B" w:rsidRDefault="0092103B" w:rsidP="0092103B">
      <w:pPr>
        <w:pStyle w:val="ListParagraph"/>
        <w:numPr>
          <w:ilvl w:val="0"/>
          <w:numId w:val="1"/>
        </w:numPr>
      </w:pPr>
      <w:r>
        <w:t>Mam</w:t>
      </w:r>
      <w:r w:rsidR="00B75C70">
        <w:t>m</w:t>
      </w:r>
      <w:r>
        <w:t>als</w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="0092103B" w:rsidRDefault="0092103B" w:rsidP="0092103B">
      <w:pPr>
        <w:pStyle w:val="ListParagraph"/>
        <w:numPr>
          <w:ilvl w:val="1"/>
          <w:numId w:val="1"/>
        </w:numPr>
      </w:pPr>
      <w:proofErr w:type="spellStart"/>
      <w:r>
        <w:t>Monotremes</w:t>
      </w:r>
      <w:proofErr w:type="spellEnd"/>
      <w:r>
        <w:t xml:space="preserve"> </w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="0092103B" w:rsidRDefault="0092103B" w:rsidP="0092103B">
      <w:pPr>
        <w:pStyle w:val="ListParagraph"/>
        <w:numPr>
          <w:ilvl w:val="2"/>
          <w:numId w:val="1"/>
        </w:numPr>
      </w:pPr>
      <w:r>
        <w:t xml:space="preserve">Platypus </w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="0092103B" w:rsidRDefault="0092103B" w:rsidP="0092103B">
      <w:pPr>
        <w:pStyle w:val="ListParagraph"/>
        <w:numPr>
          <w:ilvl w:val="3"/>
          <w:numId w:val="1"/>
        </w:numPr>
      </w:pPr>
      <w:r>
        <w:t>Duck billed</w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="0092103B" w:rsidRDefault="0092103B" w:rsidP="0092103B">
      <w:pPr>
        <w:pStyle w:val="ListParagraph"/>
        <w:numPr>
          <w:ilvl w:val="3"/>
          <w:numId w:val="1"/>
        </w:numPr>
      </w:pPr>
      <w:r>
        <w:t>Lays eggs</w:t>
      </w:r>
    </w:p>
 
Old January 5th, 2008, 08:36 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm sorry, I simply don't understand your question. You're not making it clear what you are trying to achieve or where your difficulties lie.

Try to create a smaller problem that illustrates the key points. No-one wants to spend time studying hundreds of lines of complex XML just to understand what your problem is. Create a model of the problem on a smaller scale, give the input and desired output and your best attempt at solving it, so we can understand where you are getting stuck.

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

Ok,

here is a simplified version of the xml:


<?xml version="1.0" encoding="utf-8"?>
<document>
<body>
    <paragraph>
    <text>This is some text that is not in a list.</text>
    </paragraph>


    <paragraph>
     <paraProperties>
        <paraStyle>
         ListParagraph
        </paraStyle>
        <numPr>
         <ilvl>
            0
         </ilvl>
         <numId>
            1
         </numId>
        </numPr>
     </paraProperties>
    <text>This is the first point at the highest level 0</text>
    </paragraph>

    <paragraph>
     <paraProperties>
        <paraStyle>
         ListParagraph
        </paraStyle>
        <numPr>
         <ilvl>
            1
         </ilvl>
         <numId>
            1
         </numId>
        </numPr>
     </paraProperties>
    <text>This is the first point at a nested level 1</text>
    </paragraph>

    <paragraph>
     <paraProperties>
        <paraStyle>
         ListParagraph
        </paraStyle>
        <numPr>
         <ilvl>
            1
         </ilvl>
         <numId>
            1
         </numId>
        </numPr>
     </paraProperties>
    <t>This is the second point at a nested level 1</t>
    </paragraph>

    <paragraph>
     <paraProperteis>
        <paraStyle>
         ListParagraph
        </paraStyle>
        <numPr>
         <ilvl>
            0
         </ilvl>
         <numId>
            1
         </numId>
        </numPr>
     </paraProperties>
    <text>This is the second point at highest level 0</text>
    </paragraph>

    <paragraph>
    <text>This is some more text that is not in a list, and the list has now ended.</text>
    </paragraph>

    <paragraph>
    <text>Here is some more text in another paragraph. The paragraphs can be put anywhere really.</text>
    </paragraph>


    <paragraph>
     <paraProperties>
        <paraStyle>
         ListParagraph
        </paraStyle>
        <numPr>
         <ilvl>
            0
         </ilvl>
         <numId>
            2
         </numId>
        </numPr>
     </paraProperties>
    <text>This is the first point of list number 2 at the highest level 0</text>
    </paragraph>

    <paragraph>
     <paraProperties>
        <paraStyle>
         ListParagraph
        </paraStyle>
        <numPr>
         <ilvl>
            0
         </ilvl>
         <numId>
            2
         </numId>
        </numPr>
     </paraProperties>
    <text>This is the 2nd point of list number 2 at the highest level 0</text>
    </paragraph>

    <paragraph>
     <paraProperties>
        <paraStyle>
         ListParagraph
        </paraStyle>
        <numPr>
         <ilvl>
            0
         </ilvl>
         <numId>
            2
         </numId>
        </numPr>
     </paraProperties>
    <text>This is the 3rd point of list number 2 at the highest level 0</text>
    </paragraph>

    <paragraph>
     <paraProperties>
        <paraStyle>
         ListParagraph
        </paraStyle>
        <numPr>
         <ilvl>
            1
         </ilvl>
         <numId>
            2
         </numId>
        </numPr>
     </paraProperties>
    <text>This is a nested point of list number 2 at the level 1</text>
    </paragraph>





</body>

</document>



It should output something like this:

This is some text that is not in a list.

  • This is the first point at the highest level 0

        
    •         
    • This is the first point at a nested level 1
              
    • This is the second point at a nested level 1

          


  • This is the second point at highest level 0

This is some more text that is not in a list, and the list has now ended.

Here is some more text in another paragraph. The paragraphs can be put anywhere really.

  • This is the first point of list number 2 at the highest level 0
  • This is the 2nd point of list number 2 at the highest level 0
  • This is the 3rd point of list number 2 at the highest level 0

        
    •         
    • This is a nested point of list number 2 at the level 1
          





End of out put.

Now there are a couple of things I need to point out:
1) The lists are differentiated by their numId, so the 1st had the numId of 1, and the 2nd list had the numId of 2.
2) In the XML the lists are stored in a flat format, there nodes are all at the same level, the hierarchy is only held by the values in the ilvl node.





So far I have worked on processing all lists in a document.

My main template has some html formatting code and in the body it has the following xslt:


<xsl:call-template name="doLists"/>



and doLists has the following:

    <xsl:template name="doLists">
        <xsl:for-each-group select="*" group-by="w:pPr/w:numPr/w:numId/@w:val">
            <xsl:call-template name="processItem">
                <xsl:with-param name="lvl" select="number(w:pPr/w:numPr/w:ilvl/@w:val)-1"/>
                <xsl:with-param name="pos" select="0"/>
            </xsl:call-template>
        </xsl:for-each-group>
    </xsl:template>


process item, is then called recursively from inside itself and it processes each item in the group.


Now the end goal, is to be able to take a word docx file and tranform it into html.

I have an xslt that does this, but it neglects the lists.

So far I have been able to find all the lists, process them into html, and diplay them in the right hierarchichal structure (with the correct format as well, so if it was a number, its a number, if it was a roman numeral, it is a roman numeral in the html, etc).

I need to make my xslt process the lists in place though. At the moment it just finds all the lists and processes them.

I guess what I need the xslt to be able do is:
1) go thru the xml document, and do the transformations it already has until it finds the first list item.
2) process the whole list (even though it only has the first item)
3) skip the rest of the list
4) continue processing the rest of the xml with the existing templates until it finds another list item

I hope this is clearer.

If you would actually like to see the whole xslt I wrote to process the lists in place, message me ur email address and I'll send you the xslt, and the xml I'm working with.


Thanks for your patience,
Mikey





Similar Threads
Thread Thread Starter Forum Replies Last Post
i want to modify the shopping ssomchai BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 April 3rd, 2008 01:52 AM
Help Modify GetThreadsRss kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 January 22nd, 2008 12:14 PM
Modify XML with XSLT aowen355 XSLT 4 December 26th, 2007 10:19 AM
How to modify "for-each" to "last occurrence of" ? nyctechwriter XSLT 3 October 30th, 2006 01:15 PM
How to modify hidden value? Edward King Javascript 2 January 21st, 2006 05:44 AM





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