[Home] [By Thread] [By Date] [Recent Entries]
At 2013-02-01 13:40 -0500, Mark Peters wrote:
I've trying to group certain nodes in a flat MediaWiki ML file to allow readers to show and hide the content. The grouping is based on font sizes declared in a @style attribute, which have a uniform structure across all content files. You were really close. What you weren't checking is that when the group does not match the grouping criteria for group-starting-with, then you are in the content before the first group. I hope the solution below helps ... if I haven't missed seeing anything then the output matches what you said you wanted. . . . . . . . . Ken
T:\ftemp>call xslt2 mark.xml mark.xsl
<div xmlns="http://www.w3.org/1999/xhtml"
style="margin-bottom: 15pt; margin-left: 20pt;">
<div style="blah"/>
<div style="font-family: sans-serif; font-size: 10pt;">
<span>Text</span>
</div>
<div style="font-size: 17pt;">
<span>Page Title</span>
</div>
<hr/>
<div class="NavFrame">
<div class="NavHead">Title</div>
<div class="NavContent">
<div style="font-family: sans-serif; font-size: 10pt;">
<span>Text</span>
</div>
<div style="margin-left: 5pt;">
<table/>
</div>
<div style="font-family: sans-serif; font-size: 10pt;">
<span>Text</span>
</div>
</div>
</div>
<div class="NavFrame">
<div class="NavHead">Title</div>
<div class="NavContent">
<div style="font-family: sans-serif; font-size: 10pt;">
<span>Text</span>
</div>
<div style="font-family: sans-serif; font-size: 10pt;">
<span>Text</span>
</div>
<div style="margin-left: 5pt;">
<table/>
</div>
</div>
</div>
</div>T:\ftemp>type mark.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="html" version="2.0"> <xsl:output indent="yes" omit-xml-declaration="yes"/> <xsl:template match="html:div">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each-group select="*"
group-starting-with="html:div[contains(@style,'14pt')]">
<xsl:choose>
<xsl:when test="self::html:div[contains(@style,'14pt')]">
<!--found a group-->
<div class="NavFrame">
<div class="NavHead">
<xsl:copy-of select="html:span/node()"/>
</div>
<div class="NavContent">
<xsl:copy-of select="current-group()[position()>1]"/>
</div>
</div>
</xsl:when>
<xsl:otherwise>
<!--this is the pre-amble before the first group-->
<xsl:copy-of select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template></xsl:stylesheet> T:\ftemp>rem Done!
|

Cart



