I have the following markup:
<p>
<span>
<img id="1286087c-14c9-4678-bfb6-d33fb75300dd"/>
</span>
<i>Quantity: </i>250 mg; 150<span>
<img id="15d9f37c-868f-4cc8-b656-fccdb8017ee9"/>
</span>; 170<span>
<img id="15d9f37c-868f-4cc8-b656-fccdb8017ee9"/>
</span>
</p>
What I need is I need to divide this into 2 parts:
- Need to match all child element nodes of p till i child (including i child as well). So, in this case span and i and map it to TypeA element: Quantity
- Need to match all text and element nodes which come after i child of p. Then tokenize it with semicolon space and place whatever before semicolon space into TypeB element. In this case output should be 250 mg
150
170
Also, I need make sure that template rules for span work.
Here are the template rules I used:
<xsl:mode name="marker" on-no-match="shallow-copy"/>
<xsl:mode name="analyze"/>
<xsl:template match="p">
<xsl:apply-templates select="i" mode="italic"/>
<xsl:variable name="markers" as="element(p)">
<xsl:apply-templates select="." mode="marker"/>
</xsl:variable>
<xsl:apply-templates select="$marker" mode="wrap"/>
</xsl:template>
<xsl:template match="p/node()[not(self::i)]" mode="marker">
<xsl:apply-templates select="analyze-string(., ';s')" mode="analyze-strength"/>
</xsl:template>
<xsl:template match="*:match" mode="analyze-strength">
<semicolon/>
</xsl:template>
<xsl:template match="p" mode="wrap">
<xsl:for-each-group select="node()" group-ending-with="semicolon">
<xsl:element name="TypeB">
<xsl:apply-templates select="current-group()"/>
</xsl:element>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="semicolon"/>
<xsl:template match="p/i" mode="italic">
<xsl:element name="TypeA">
<xsl:apply-templates select="preceding-sibling::span"/>
<xsl:value-of select="substring-before(.,':')"/>
</xsl:element>
</xsl:template>