Hi,
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.
Essentially, I'm trying to group each <div/> node where the @style
contains "14pt" with its following siblings. Some of the siblings have
other font sizes smaller than 14pt; others have no declared font sizes
because they wrap other nodes, such as tables.
Each grouping will have the following structure:
<div class="NavFrame"> [replaces <div style="font-size: 14pt;">]
<div class="NavHead">Title</div> [replaces <span>Title</span>]
<div class="NavContent">
.. [following siblings of <div style="font-size: 14pt;">]
</div>
</div>
Input:
<div style="margin-bottom: 15pt; margin-left: 20pt;"
xmlns="http://www.w3.org/1999/xhtml">
<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 style="font-size: 14pt;">
<span>Title</span>
</div>
<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 style="font-size: 14pt;">
<span>Title</span>
</div>
<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>
Desired output:
<div style="margin-bottom: 15pt; margin-left: 20pt;"
xmlns="http://www.w3.org/1999/xhtml">
<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>
Here's my draft stylesheet.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/1999/xhtml" version="2.0">
<xsl:output indent="yes" include-content-type="no"
omit-xml-declaration="yes"/>
<!-- This stylesheet ... -->
<!-- Copy all elements and attributes from the source document -->
<xsl:output indent="yes"/>
<!-- Insert collabsible CSS classes into the .wiki topic files -->
<xsl:template match="html:div[1]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each-group select="*" group-starting-with="html:div[
contains(@style,'14pt')]">
<div class="NavFrame">
<div class="NavHead">
<xsl:value-of select="span"/>
</div>
<div class="NavContent">
<xsl:apply-templates select="current-group()"/>
</div>
</div>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
And the current output:
<div xmlns="http://www.w3.org/1999/xhtml" style="margin-bottom: 15pt;
margin-left: 20pt;">
<div xmlns="" xmlns:html="http://www.w3.org/1999/xhtml" class="NavFrame">
<div class="NavHead"/>
<div class="NavContent">
<div xmlns="http://www.w3.org/1999/xhtml" style="blah"/>
Text
Page Title
</div>
</div>
<div xmlns="" xmlns:html="http://www.w3.org/1999/xhtml" class="NavFrame">
<div class="NavHead"/>
<div class="NavContent">
Title
Text
Text
</div>
</div>
<div xmlns="" xmlns:html="http://www.w3.org/1999/xhtml" class="NavFrame">
<div class="NavHead"/>
<div class="NavContent">
Title
Text
Text
</div>
</div>
</div>
The stylesheet currently inserts the <div class="NavFrame"/> node at
the beginning of the output file and also groups nodes where the
starting <div/> node/@style attribute doesn't contain "14pt" -- for
example, <div style="font-size: 17pt;">. Also, the output child nodes
contain text only.
Any help would be appreciated.
Thanks!
Mark
--
Senior technical writer
Saba Software, Inc.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--