I have this xml input:
<div id="584175">
<p>1.2 Modes</p>
<p>Some content</p>
<div class="analyze_visual" lookup="2.1.2.2" av_itemIDnum="584177"
nextExposID="584176">
<p>Analyzing the Visual</p>
<div class="av" type="analyze">
<img alt="" src="http://assets.xxx.com/xxx.png"/>
<p class="caption">Figure 2-2</p>
</div>
</div>
<p>Ethics</p>
<p>More content</p>
</div>
I need to divide it into three parts with any <div class=“analyze_visual”> as
the trigger:
<div id="584175”>
<part num=“1” globalNum=“584175">
<p>1.2 Modes</p>
<p>Some content</p>
</part>
<part num="2">
<div class="analyze_visual" lookup="2.1.2.2" av_itemIDnum="584177"
nextExposID="584176">
<p>Analyzing the Visual</p>
<div class="av" type="analyze">
<img alt="" src="http://assets.xxx.com/xxx.png"/>
<p class="caption">Figure 2-2</p>
</div>
</div>
</part>
<part num="3" globalNum="584176">
<p>Ethics</p>
<p>more content</p>
</part>
</div>
I am using for-each-group() group-ending-with=“div[@class=‘analyze_visual’] to
accomplish the creation of the parts.
The Issue: I am having trouble transferring the attribute nextExposID into the
third part. Here is the stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
version="3.0">
<xsl:template match="div">
<xsl:variable name="exploreExposID">
<xsl:value-of select="@id"/>
</xsl:variable>
<div>
<xsl:copy-of select="@*"/>
<xsl:for-each-group select="*"
group-ending-with="div[@class='analyze_visual']">
<xsl:variable name="part3ID">
<xsl:value-of
select="current-group()[self::div[@class='analyze_visual']]/@nextExposID"></xsl:value-of>
</xsl:variable>
<xsl:choose>
<xsl:when
test="current-group()[self::div[@class='analyze_visual']]">
<part num="1" globalNumn="{$exploreExposID}">
<xsl:copy-of
select="current-group()[not(self::div[@class='analyze_visual'])][not(self::h9)]"/>
</part>
<part num="2" globalNum="{$part3ID}">
<xsl:copy-of
select="current-group()[self::div[@class='analyze_visual']]"></xsl:copy-of>
</part>
</xsl:when>
<xsl:otherwise>
<part num="3">
<xsl:attribute name=“globalNum">
<xsl:value-of select="$part3ID"/>
</xsl:attribute>
<xsl:copy-of select="current-group()"/>
</part>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</div>
</xsl:template>
</xsl:stylesheet>
Notice in the result below that the variable part3ID appears in part 2 just
fine, but it doesn’t display in part 3. I suspect this is due to the
<otherwise> of the xsl:choose. This seems strange to me, since I have declared
the variable outside the xsl:choose.
My questions
Is there a way to pass that variable to part 3?
Or, is there a better way to create the parts I need?
(I know that my numbering of the parts is clunky. I will address the numbering
to accommodate situations with more than one <div> after I solve this issue.)
Output modified slightly with returns to improve readability.
<div id="584175”>
<part num="1" globalNumn="584175">
<p>1.2 Modes</p>
<p>Some content</p>
</part>
<part num="2" globalNum="584176">
<div class="analyze_visual"
lookup="2.1.2.2"
av_itemIDnum="584177"
nextExposID="584176">
<p>Analyzing the Visual</p>
<div class="av" type="analyze">
<img alt="" src="http://assets.xxx.com/xxx.png"/>
<p class="caption">Figure 2-2</p>
</div>
</div>
</part>
<part num="3" globalNum="">
<p>Ethics</p>
<p>More content</p>
</part>
</div>
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--