 |
| 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
|
|
|
|

April 10th, 2011, 07:45 PM
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
XSLT 2.0 Nesting lists inside lists by group
I'm attempting to build a nested list inside a list using XSLT. I'm not sure if a Meunchian approach would be best here or if the grouping function in 2.0 is better suited. Some of the lists will have second levels or possible a third. I'm not using template matching here because I need to iterate through the same section of xml a couple of times.
The source looks like:
Code:
<draw:text-box>
<text:list text:style-name="a1275">
<text:list-item><text:p text:style-name="a1274" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1272" text:class-names="">Bullet in list</text:span><text:span text:style-name="a1273" text:class-names="">:</text:span></text:p></text:list-item>
</text:list><text:list text:style-name="a1282"><text:list-item><text:list text:style-name="a1282"><text:list-item><text:p text:style-name="a1281" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1276" text:class-names="">First sub-bullet</text:span><text:span text:style-name="a1277" text:class-names="">:<text:s text:c="1"/></text:span><text:span text:style-name="a1278" text:class-names=""></text:span><text:span text:style-name="a1279" text:class-names=""></text:span><text:span text:style-name="a1280" text:class-names=""></text:span></text:p></text:list-item></text:list></text:list-item></text:list>
<text:list text:style-name="a1289"><text:list-item><text:list text:style-name="a1289"><text:list-item><text:p text:style-name="a1288" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1283" text:class-names="">Second sub-bullet</text:span><text:span text:style-name="a1284" text:class-names="">:<text:s text:c="1"/></text:span><text:span text:style-name="a1285" text:class-names=""></text:span><text:span text:style-name="a1286" text:class-names=""></text:span><text:span text:style-name="a1287" text:class-names=""></text:span></text:p></text:list-item></text:list></text:list-item></text:list>
</text:list-item></text:list><text:list text:style-name="a1311"><text:list-item><text:list text:style-name="a1311"><text:list-item><text:list text:style-name="a1311"><text:list-item><text:p text:style-name="a1310" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1308" text:class-names="">Second bullet</text:span><text:span text:style-name="a1309" text:class-names="">:</text:span></text:p></text:list-item></text:list></text:list-item></text:list></text:list-item></text:list>
<text:list text:style-name="a1320"><text:list-item><text:list text:style-name="a1320"><text:list-item><text:p text:style-name="a1319" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1312" text:class-names="">First sub-bullet in new list<text:s text:c="1"/></text:span><text:span text:style-name="a1313" text:class-names="">a<text:s text:c="1"/></text:span><text:span text:style-name="a1314" text:class-names=""></text:span><text:span text:style-name="a1315" text:class-names="">:<text:s text:c="1"/></text:span><text:span text:style-name="a1316" text:class-names=""></text:span><text:span text:style-name="a1317" text:class-names=""></text:span><text:span text:style-name="a1318" text:class-names=""></text:span></text:p></text:list-item></text:list></text:list-item></text:list>
</draw:text-box>
My code looks like:
Code:
<unordered-list>
<xsl:for-each select="draw:text-box/text:list">
<xsl:choose>
<xsl:when test="text:list-item[not(text:list)][text:p/text:span/text()]">
<xsl:variable name="bulletString" select="text:list-item/text:p/text:span"/>
<list><xsl:value-of select="$bulletString"/></list>
</xsl:when>
<xsl:when test=".[not(preceding-sibling::text:list/text:list-item/text:list)]">
<unordered-list>
<xsl:for-each select=".[following-sibling::text:list/text:list-item/text:list]"> <xsl:variable name="subBulletString" select="text:list-item/text:list/text:list-item/text:p/text:span"/>
<list><xsl:value-of select="$subBulletString"/></list>
<xsl:for-each select="following-sibling::text:list[text:list-item/text:list]">
<list><xsl:value-of select="text:list-item/text:list/text:list-item/text:p/text:span"/></list>
</xsl:for-each>
</xsl:for-each>
</unordered-list>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</unordered-list>
Expected output is:
Code:
<unordered-list>
<list>Bullet in list</list>
<unordered-list>
<list>First sub-bullet</list>
<list>Second sub-bullet</list>
</unordered-list>
<list>Second bullet</list>
<unordered-list>
<list>First sub-bullet in new list</list>
</unordered-list>
</unordered-list>
Any pointers on getting consistent results is appreciated. I can't seem to get this tweaked quite right to pull the content I'm after from an ODP document.
|
|

April 11th, 2011, 02:51 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
I couldn't even parse your example input as valid XML (even if I added the namespace declarations) so I really can't help you.
|
|

April 11th, 2011, 02:16 PM
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
My mistake, I must have had an error in the syntax.
Here's the updated code with namespace:
Code:
<xsl:stylesheet
version="2.0"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
xmlns:math="http://www.w3.org/1998/Math/MathML"
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:dom="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
office:class="text"
office:version="1.0"
exclude-result-prefixes="#all">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<unordered-list>
<xsl:for-each select="office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:text-box/text:list">
<xsl:choose>
<xsl:when test="text:list-item[not(text:list)][text:p/text:span/text()]">
<xsl:variable name="bulletString" select="text:list-item/text:p/text:span"/>
<list><xsl:value-of select="$bulletString"/></list>
</xsl:when>
<xsl:when test=".[not(preceding-sibling::text:list/text:list-item/text:list)]">
<unordered-list>
<xsl:for-each select=".[following-sibling::text:list/text:list-item/text:list]"> <xsl:variable name="subBulletString" select="text:list-item/text:list/text:list-item/text:p/text:span"/>
<list><xsl:value-of select="$subBulletString"/></list>
<xsl:for-each select="following-sibling::text:list[text:list-item/text:list]">
<list><xsl:value-of select="text:list-item/text:list/text:list-item/text:p/text:span"/></list>
</xsl:for-each>
</xsl:for-each>
</unordered-list>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</unordered-list>
</xsl:template>
</xsl:stylesheet>
And here's the updated source:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<office:document-content xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">
<office:body><office:presentation><draw:page draw:name="Slide1" draw:style-name="a1271" draw:master-page-name="Master1-Layout3-cust-Bullet" presentation:presentation-page-layout-name="Master1-PPL3"><draw:frame draw:id="id122" presentation:style-name="a1331" draw:name="Content Placeholder 1" svg:x="0.31258in" svg:y="1.14583in" svg:width="9.33243in" svg:height="3.96262in" presentation:class="outline" presentation:placeholder="false">
<draw:text-box>
<text:list text:style-name="a1275">
<text:list-item><text:p text:style-name="a1274" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1272" text:class-names="">Bullet in list</text:span><text:span text:style-name="a1273" text:class-names=""></text:span></text:p></text:list-item></text:list>
<text:list text:style-name="a1282"><text:list-item><text:list text:style-name="a1282"><text:list-item><text:p text:style-name="a1281" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1276" text:class-names="">First sub-bullet</text:span><text:span text:style-name="a1277" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1278" text:class-names=""></text:span><text:span text:style-name="a1279" text:class-names=""></text:span><text:span text:style-name="a1280" text:class-names=""></text:span></text:p></text:list-item></text:list></text:list-item></text:list>
<text:list text:style-name="a1289"><text:list-item><text:list text:style-name="a1289"><text:list-item><text:p text:style-name="a1288" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1283" text:class-names="">Second sub-bullet</text:span><text:span text:style-name="a1284" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1285" text:class-names=""></text:span><text:span text:style-name="a1286" text:class-names=""></text:span><text:span text:style-name="a1287" text:class-names=""></text:span></text:p></text:list-item></text:list></text:list-item></text:list>
<text:list text:style-name="a1298"><text:list-item><text:list text:style-name="a1298"><text:list-item><text:p text:style-name="a1297" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1290" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1291" text:class-names=""></text:span><text:span text:style-name="a1292" text:class-names=""></text:span><text:span text:style-name="a1293" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1294" text:class-names=""></text:span><text:span text:style-name="a1295" text:class-names=""></text:span><text:span text:style-name="a1296" text:class-names=""></text:span></text:p></text:list-item></text:list></text:list-item></text:list>
<text:list text:style-name="a1307"><text:list-item><text:list text:style-name="a1307"><text:list-item><text:p text:style-name="a1306" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1299" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1300" text:class-names=""></text:span><text:span text:style-name="a1301" text:class-names=""></text:span><text:span text:style-name="a1302" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1303" text:class-names=""></text:span><text:span text:style-name="a1304" text:class-names=""></text:span><text:span text:style-name="a1305" text:class-names=""></text:span></text:p></text:list-item></text:list></text:list-item></text:list>
<text:list text:style-name="a1311"><text:list-item><text:list text:style-name="a1311"><text:list-item><text:list text:style-name="a1311"><text:list-item><text:p text:style-name="a1310" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1308" text:class-names="">Second bullet</text:span><text:span text:style-name="a1309" text:class-names=""></text:span></text:p></text:list-item></text:list></text:list-item></text:list></text:list-item></text:list>
<text:list text:style-name="a1320"><text:list-item><text:list text:style-name="a1320"><text:list-item><text:p text:style-name="a1319" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1312" text:class-names="">First sub-bullet in new list<text:s text:c="1"/></text:span><text:span text:style-name="a1313" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1314" text:class-names=""></text:span><text:span text:style-name="a1315" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1316" text:class-names=""></text:span><text:span text:style-name="a1317" text:class-names=""></text:span><text:span text:style-name="a1318" text:class-names=""></text:span></text:p></text:list-item></text:list></text:list-item></text:list>
<text:list text:style-name="a1330"><text:list-item><text:list text:style-name="a1330"><text:list-item><text:p text:style-name="a1329" text:class-names="" text:cond-style-name=""><text:span text:style-name="a1321" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1322" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1323" text:class-names=""></text:span><text:span text:style-name="a1324" text:class-names=""><text:s text:c="1"/></text:span><text:span text:style-name="a1325" text:class-names=""></text:span><text:span text:style-name="a1326" text:class-names=""></text:span><text:span text:style-name="a1327" text:class-names=""></text:span><text:span text:style-name="a1328" text:class-names=""/></text:p></text:list-item></text:list></text:list-item></text:list></draw:text-box><svg:desc/></draw:frame></draw:page></office:presentation></office:body>
</office:document-content>
And I'm still after the same expected output:
Code:
<unordered-list>
<list>Bullet in list</list>
<unordered-list>
<list>First sub-bullet</list>
<list>Second sub-bullet</list>
</unordered-list>
<list>Second bullet</list>
<unordered-list>
<list>First sub-bullet in new list</list>
</unordered-list>
</unordered-list>
I'm starting to get them grouped, but my method quickly falls apart once there are re-occurrences of sub-levels.
|
|

April 12th, 2011, 07:42 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
If you simply want to transform "text: list" elements into "unordered-list" elements and "text: list-item" elements into "list" elements then the following should do:
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
exclude-result-prefixes="text"
version="1.0">
<xsl:template match="text:list">
<unordered-list>
<xsl:apply-templates/>
</unordered-list>
</xsl:template>
<xsl:template match="text:list-item">
<list>
<xsl:apply-templates/>
</list>
</xsl:template>
</xsl:stylesheet>
If that is not what you want to do then please explain in more details how the posted output format relates to the input format, I am not sure when you want to transform elements and when you want to strip them.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

April 12th, 2011, 10:45 AM
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thanks for your response Martin. I don't think the template match on the list and list-items will maintain the desired structure. Let me try to clarify.
I'm attempting build a bulleted list that contains sub-bullets in some of the list items. The trouble comes when embedding an unordered list inside an unordered list.
Code:
<unordered-list>
<list>Item 1</list>
<unordered-list>
<list>Sub-Item 1</list>
<list>Sub-Item 2</list>
</unordered-list>
<list>Item 2</list>
<list>Item 3</list>
</unordered-list>
So when I'm building these nested items, I need to keep straight the level where each <list> is located. In the source, I have some text:list/text:list-item and others at text:list/text:list-item/text:list/text:list-item. In some cases, the source may even go a level deeper.
I'm not worried right now about stripping empty elements, I'm just stuck on how to group an unordered list inside an ordered list. I just need it to maintain the structure and order from the source (i.e. some <list> elements are nested two-levels deep). It seems like I would need to use a grouping function?
|
|

April 12th, 2011, 11:42 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
I think you underestimate the approach I have posted, it maintains the input structure, it simply transforms the elements for which I wrote templates. So the input you posted (only indented to be able to read it and recognize the structure)
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<office:document-content xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">
<office:body>
<office:presentation>
<draw:page draw:name="Slide1" draw:style-name="a1271" draw:master-page-name="Master1-Layout3-cust-Bullet" presentation:presentation-page-layout-name="Master1-PPL3">
<draw:frame draw:id="id122" presentation:style-name="a1331" draw:name="Content Placeholder 1" svg:x="0.31258in" svg:y="1.14583in" svg:width="9.33243in" svg:height="3.96262in" presentation:class="outline" presentation:placeholder="false">
<draw:text-box>
<text:list text:style-name="a1275">
<text:list-item>
<text:p text:style-name="a1274" text:class-names="" text:cond-style-name="">
<text:span text:style-name="a1272" text:class-names="">Bullet in list</text:span>
<text:span text:style-name="a1273" text:class-names=""></text:span>
</text:p>
</text:list-item>
</text:list>
<text:list text:style-name="a1282">
<text:list-item>
<text:list text:style-name="a1282">
<text:list-item>
<text:p text:style-name="a1281" text:class-names="" text:cond-style-name="">
<text:span text:style-name="a1276" text:class-names="">First sub-bullet</text:span>
<text:span text:style-name="a1277" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1278" text:class-names=""></text:span>
<text:span text:style-name="a1279" text:class-names=""></text:span>
<text:span text:style-name="a1280" text:class-names=""></text:span>
</text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1289">
<text:list-item>
<text:list text:style-name="a1289">
<text:list-item>
<text:p text:style-name="a1288" text:class-names="" text:cond-style-name="">
<text:span text:style-name="a1283" text:class-names="">Second sub-bullet</text:span>
<text:span text:style-name="a1284" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1285" text:class-names=""></text:span>
<text:span text:style-name="a1286" text:class-names=""></text:span>
<text:span text:style-name="a1287" text:class-names=""></text:span>
</text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1298">
<text:list-item>
<text:list text:style-name="a1298">
<text:list-item>
<text:p text:style-name="a1297" text:class-names="" text:cond-style-name="">
<text:span text:style-name="a1290" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1291" text:class-names=""></text:span>
<text:span text:style-name="a1292" text:class-names=""></text:span>
<text:span text:style-name="a1293" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1294" text:class-names=""></text:span>
<text:span text:style-name="a1295" text:class-names=""></text:span>
<text:span text:style-name="a1296" text:class-names=""></text:span>
</text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1307">
<text:list-item>
<text:list text:style-name="a1307">
<text:list-item>
<text:p text:style-name="a1306" text:class-names="" text:cond-style-name="">
<text:span text:style-name="a1299" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1300" text:class-names=""></text:span>
<text:span text:style-name="a1301" text:class-names=""></text:span>
<text:span text:style-name="a1302" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1303" text:class-names=""></text:span>
<text:span text:style-name="a1304" text:class-names=""></text:span>
<text:span text:style-name="a1305" text:class-names=""></text:span>
</text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1311">
<text:list-item>
<text:list text:style-name="a1311">
<text:list-item>
<text:list text:style-name="a1311">
<text:list-item>
<text:p text:style-name="a1310" text:class-names="" text:cond-style-name="">
<text:span text:style-name="a1308" text:class-names="">Second bullet</text:span>
<text:span text:style-name="a1309" text:class-names=""></text:span>
</text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1320">
<text:list-item>
<text:list text:style-name="a1320">
<text:list-item>
<text:p text:style-name="a1319" text:class-names="" text:cond-style-name="">
<text:span text:style-name="a1312" text:class-names="">First sub-bullet in new list<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1313" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1314" text:class-names=""></text:span>
<text:span text:style-name="a1315" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1316" text:class-names=""></text:span>
<text:span text:style-name="a1317" text:class-names=""></text:span>
<text:span text:style-name="a1318" text:class-names=""></text:span>
</text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1330">
<text:list-item>
<text:list text:style-name="a1330">
<text:list-item>
<text:p text:style-name="a1329" text:class-names="" text:cond-style-name="">
<text:span text:style-name="a1321" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1322" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1323" text:class-names=""></text:span>
<text:span text:style-name="a1324" text:class-names="">
<text:s text:c="1"/>
</text:span>
<text:span text:style-name="a1325" text:class-names=""></text:span>
<text:span text:style-name="a1326" text:class-names=""></text:span>
<text:span text:style-name="a1327" text:class-names=""></text:span>
<text:span text:style-name="a1328" text:class-names=""/>
</text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
</draw:text-box>
<svg:desc/>
</draw:frame>
</draw:page>
</office:presentation>
</office:body>
</office:document-content>
is transformed with the stylesheet
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
exclude-result-prefixes="text"
version="1.0">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="text:list">
<unordered-list>
<xsl:apply-templates/>
</unordered-list>
</xsl:template>
<xsl:template match="text:list-item">
<list>
<xsl:apply-templates/>
</list>
</xsl:template>
</xsl:stylesheet>
into
Code:
<?xml version="1.0" encoding="utf-8"?>
<unordered-list>
<list>Bullet in list</list>
</unordered-list>
<unordered-list>
<list>
<unordered-list>
<list>First sub-bullet</list>
</unordered-list>
</list>
</unordered-list>
<unordered-list>
<list>
<unordered-list>
<list>Second sub-bullet</list>
</unordered-list>
</list>
</unordered-list>
<unordered-list>
<list>
<unordered-list>
<list/>
</unordered-list>
</list>
</unordered-list>
<unordered-list>
<list>
<unordered-list>
<list/>
</unordered-list>
</list>
</unordered-list>
<unordered-list>
<list>
<unordered-list>
<list>
<unordered-list>
<list>Second bullet</list>
</unordered-list>
</list>
</unordered-list>
</list>
</unordered-list>
<unordered-list>
<list>
<unordered-list>
<list>First sub-bullet in new list</list>
</unordered-list>
</list>
</unordered-list>
<unordered-list>
<list>
<unordered-list>
<list/>
</unordered-list>
</list>
</unordered-list>
If that output is not what you want for the sample you posted then try to explain in more details which elements you want to group together and/or which elements you want to strip.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

April 12th, 2011, 12:07 PM
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
It's definitely a good approach, but it wraps an <unordered-list> around each individual <list> element. I have to be able to group <list> elements at the same level together. So something like this (by editing the output you just produced):
Code:
<?xml version="1.0" encoding="utf-8"?>
<unordered-list>
<list>Bullet in list</list>
<unordered-list>
<list>First sub-bullet</list>
<list>Second sub-bullet</list>
</unordered-list>
<list>Second bullet</list>
<unordered-list>
<list>First sub-bullet in new list</list>
</unordered-list>
</unordered-list>
|
|

April 12th, 2011, 12:08 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Your current sample only contains 1 text:list/text:list-item followed by multiple text:list/text:list-item/text:list/text:list-item items, only two of which have any text in them.
This makes it very hard for us to see how it relates to the expected output you posted, which has multiple bullets and sub-bullets.
|
|

April 12th, 2011, 12:40 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
I am also struggling to see how the output you want relates to the input you posted. The output you ask for has
Code:
<list>Bullet in list</list>
and
Code:
<list>Second bullet</list>
on the same level yet in the input document these are at different nesting levels.
If you want to group the elements on the same level in the input then the following XSLT 2.0
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
exclude-result-prefixes="text"
version="2.0">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*[text:list]">
<xsl:for-each-group select="*" group-adjacent="boolean(self::text:list)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<unordered-list>
<xsl:apply-templates select="current-group()/node()"/>
</unordered-list>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="text:list-item">
<list>
<xsl:apply-templates/>
</list>
</xsl:template>
</xsl:stylesheet>
might help, it produces
Code:
<unordered-list>
<list>Bullet in list</list>
<unordered-list>
<list>First sub-bullet</list>
</unordered-list>
<unordered-list>
<list>Second sub-bullet</list>
</unordered-list>
<unordered-list>
<list/>
</unordered-list>
<unordered-list>
<list/>
</unordered-list>
<unordered-list>
<unordered-list>
<list>Second bullet</list>
</unordered-list>
</unordered-list>
<unordered-list>
<list>First sub-bullet in new list</list>
</unordered-list>
<unordered-list>
<list/>
</unordered-list>
</unordered-list>
but I so far don't understand when you want to strip or merge levels or how to express that programmatically.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|
The Following User Says Thank You to Martin Honnen For This Useful Post:
|
|
|

April 12th, 2011, 12:50 PM
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Yeah, the content is so repetitive that it becomes increasingly confusing even as I look at it. It's very unwieldy. Let me give a final try at explaining.
Updated source to look like what I've been dealing with:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<office:document-content xmlns:dom="http://www.w3.org/2001/xml-events"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">
<office:body>
<office:presentation>
<draw:page draw:name="Slide1" draw:style-name="a1271"
draw:master-page-name="Master1-Layout3-cust-Bullet"
presentation:presentation-page-layout-name="Master1-PPL3">
<draw:frame>
<draw:text-box>
<text:list text:style-name="a1275">
<text:list-item>
<text:p text:style-name="a1274" text:class-names="" text:cond-style-name=""
><text:span text:style-name="a1272" text:class-names="">First
Bullet</text:span><text:span text:style-name="a1273" text:class-names=""
>:</text:span></text:p>
</text:list-item>
</text:list>
<text:list text:style-name="a1282">
<text:list-item>
<text:list text:style-name="a1282">
<text:list-item>
<text:p text:style-name="a1281" text:class-names="" text:cond-style-name=""
><text:span text:style-name="a1276" text:class-names=""
>Sub-bullet</text:span><text:span text:style-name="a1277"
text:class-names="">1:<text:s text:c="1"/></text:span><text:span
text:style-name="a1278" text:class-names="">info</text:span><text:span
text:style-name="a1279" text:class-names="">for</text:span><text:span
text:style-name="a1280" text:class-names="">sub-bullet
1</text:span></text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1289">
<text:list-item>
<text:list text:style-name="a1289">
<text:list-item>
<text:p text:style-name="a1288" text:class-names="" text:cond-style-name=""
><text:span text:style-name="a1283" text:class-names=""
>Sub-bullet</text:span><text:span text:style-name="a1284"
text:class-names="">2:<text:s text:c="1"/></text:span><text:span
text:style-name="a1285" text:class-names="">info</text:span><text:span
text:style-name="a1286" text:class-names="">for</text:span><text:span
text:style-name="a1287" text:class-names="">sub-bullet
2</text:span></text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1298">
<text:list-item>
<text:list text:style-name="a1298">
<text:list-item>
<text:p text:style-name="a1297" text:class-names="" text:cond-style-name=""
><text:span text:style-name="a1290" text:class-names="">Sub-bullet<text:s
text:c="1"/></text:span><text:span text:style-name="a1291"
text:class-names="">3</text:span><text:span text:style-name="a1292"
text:class-names="">:</text:span><text:span text:style-name="a1293"
text:class-names="">info<text:s text:c="1"/></text:span><text:span
text:style-name="a1294" text:class-names="">for</text:span><text:span
text:style-name="a1295" text:class-names="">sub-bullet</text:span><text:span
text:style-name="a1296" text:class-names="">3</text:span></text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1307">
<text:list-item>
<text:list text:style-name="a1307">
<text:list-item>
<text:p text:style-name="a1306" text:class-names="" text:cond-style-name=""
><text:span text:style-name="a1299" text:class-names="">Sub-bullet <text:s
text:c="1"/></text:span><text:span text:style-name="a1300"
text:class-names="">4</text:span><text:span text:style-name="a1301"
text:class-names="">:</text:span><text:span text:style-name="a1302"
text:class-names="">more info<text:s text:c="1"/></text:span><text:span
text:style-name="a1303" text:class-names="">for
</text:span><text:span text:style-name="a1304" text:class-names=""
>sub-bullet</text:span><text:span text:style-name="a1305" text:class-names=""
>4</text:span></text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1311">
<text:list-item>
<text:list text:style-name="a1311">
<text:list-item>
<text:list text:style-name="a1311">
<text:list-item>
<text:p text:style-name="a1310" text:class-names="" text:cond-style-name=""
><text:span text:style-name="a1308" text:class-names="">Second
bullet</text:span><text:span text:style-name="a1309" text:class-names=""
>:</text:span></text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1320">
<text:list-item>
<text:list text:style-name="a1320">
<text:list-item>
<text:p text:style-name="a1319" text:class-names="" text:cond-style-name=""
><text:span text:style-name="a1312" text:class-names="">Sub-bullet<text:s
text:c="1"/></text:span><text:span text:style-name="a1313"
text:class-names="">5<text:s text:c="1"/></text:span><text:span
text:style-name="a1314" text:class-names="">:</text:span><text:span
text:style-name="a1315" text:class-names="">more<text:s text:c="1"
/></text:span><text:span text:style-name="a1316" text:class-names=""
>informa</text:span><text:span text:style-name="a1317" text:class-names=""
>tion</text:span><text:span text:style-name="a1318" text:class-names="">for
sub-bullet 5</text:span></text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
<text:list text:style-name="a1330">
<text:list-item>
<text:list text:style-name="a1330">
<text:list-item>
<text:p text:style-name="a1329" text:class-names="" text:cond-style-name=""
><text:span text:style-name="a1321" text:class-names="">Sub-bullet<text:s
text:c="1"/></text:span><text:span text:style-name="a1322"
text:class-names="">6<text:s text:c="1"/></text:span><text:span
text:style-name="a1323" text:class-names="">:</text:span><text:span
text:style-name="a1324" text:class-names="">more<text:s text:c="1"
/></text:span><text:span text:style-name="a1325" text:class-names=""
>information</text:span><text:span text:style-name="a1326"
text:class-names="">on</text:span><text:span text:style-name="a1327"
text:class-names="">sub-bullet 6</text:span><text:span
text:style-name="a1328" text:class-names=""/></text:p>
</text:list-item>
</text:list>
</text:list-item>
</text:list>
</draw:text-box>
</draw:frame>
</draw:page>
</office:presentation>
</office:body>
</office:document-content>
Transforming with this:
Code:
<xsl:stylesheet
version="2.0"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
xmlns:math="http://www.w3.org/1998/Math/MathML"
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:dom="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
office:class="text"
office:version="1.0"
exclude-result-prefixes="#all">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<unordered-list>
<xsl:for-each select="office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:text-box/text:list">
<xsl:choose>
<xsl:when test="text:list-item[not(text:list)][text:p/text:span/text()]">
<xsl:variable name="bulletString" select="text:list-item/text:p/text:span"/>
<list><xsl:value-of select="$bulletString"/></list>
</xsl:when>
<xsl:when test=".[not(preceding-sibling::text:list/text:list-item/text:list)]">
<unordered-list>
<xsl:for-each select=".[following-sibling::text:list/text:list-item/text:list]"> <xsl:variable name="subBulletString" select="text:list-item/text:list/text:list-item/text:p/text:span"/>
<list><xsl:value-of select="$subBulletString"/></list>
<xsl:for-each select="following-sibling::text:list[text:list-item/text:list]">
<list><xsl:value-of select="text:list-item/text:list/text:list-item/text:p/text:span"/></list>
</xsl:for-each>
</xsl:for-each>
</unordered-list>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</unordered-list>
</xsl:template>
</xsl:stylesheet>
Gives me an output of:
Code:
<unordered-list>
<list>First Bullet :</list>
<unordered-list>
<list>Sub-bullet 1: info for sub-bullet 1</list>
<list>Sub-bullet 2: info for sub-bullet 2</list>
<list>Sub-bullet 3 : info for sub-bullet 3</list>
<list>Sub-bullet 4 : more info for sub-bullet 4</list>
<list/>
<list>Sub-bullet 5 : more informa tion for sub-bullet 5</list>
<list>Sub-bullet 6 : more information on sub-bullet 6 </list>
</unordered-list>
</unordered-list>
But that output SHOULD look like this:
Code:
<unordered-list>
<list>First
Bullet :</list>
<unordered-list>
<list>Sub-bullet 1: info for sub-bullet 1</list>
<list>Sub-bullet 2: info for sub-bullet 2</list>
<list>Sub-bullet 3 : info for sub-bullet 3</list>
<list>Sub-bullet 4 : more info for sub-bullet 4</list>
</unordered-list>
<list> Second Bullet </list>
<unordered-list>
<list>Sub-bullet 5 : more informa tion for sub-bullet 5</list>
<list>Sub-bullet 6 : more information on sub-bullet 6 </list>
</unordered-list>
</unordered-list>
Apologies if it's still too confusing to continue. Thanks for your help up to this point.
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| foreach with two lists |
silasla |
C# |
13 |
May 2nd, 2008 12:27 PM |
| Multiple Dropdown lists inside a datagrid |
gayatricbe |
ASP.NET 2.0 Basics |
3 |
October 24th, 2007 04:09 PM |
| Lists |
rickyoung |
Pro Visual Basic 2005 |
0 |
November 24th, 2006 09:04 AM |
| Lists |
Martyn |
Forum and Wrox.com Feedback |
9 |
June 6th, 2003 11:03 AM |
| Email Lists |
Jeff Mason |
Forum and Wrox.com Feedback |
43 |
June 5th, 2003 11:39 AM |
|
 |