Split XML with XSLT 1.0 at the location of a particular tag, and maintain HTML markup throughout results -
i need transform next xml splitting @ <hr/> tag. content on either side of split should stored params, , output within separate divs.
i'm running several issues:
1) can't seem utilize <hr/> tag separator this. assume that's due parser stripping tag prior setting new params? there workaround this? have command on xml output within <bodytext> node, , while utilize specified string instead, <hr/> tag makes more reliable flag maintenance-wise.
2) while <xsl:copy-of select="$desc"/> produces total contents html markup intact (which need), $shortdesc , $longdesc both homecoming bare / stripped text content. how can retain html markup?
essentially need split xml @ point of <hr/> tag, , re-create before , after contents separate divs markup intact.
i've seen few posts challenges quite close this, each different plenty i've been unable resolve.
the xml:
<bodytext> <p>lorem ipsum short</p> <hr/> <p>lorem ipsum long</p> </bodytext> *and please note xml feed admin-generated, basic example. actual feed not dependable, there <hr/> split should occur.
the xsl:
<xsl:template name="expandcontent_main"> <xsl:param name="desc" select="/bodytext"/> <xsl:param name="separator" select="'<hr/>'"/> <xsl:param name="shortdesc" select="substring-before($desc, $separator)"/> <xsl:param name="longdesc" select="substring-after($desc, $separator)"/> <div class="short-description"> <xsl:copy-of select="$shortdesc"/> </div> <div class="long-description"> <xsl:copy-of select="$longdesc"/> </div> </xsl:template> the expected output:
<div class="short-description"> <p>lorem ipsum short</p> </div> <div class="long-description"> <p>lorem ipsum long</p> </div>
<xsl:template match="bodytext"> <div class="short-description"> <xsl:copy-of select="node()[following-sibling::hr]"/> </div> <div class="long-description"> <xsl:copy-of select="node()[preceding-sibling::hr]"/> </div> </xsl:template>
html xml xslt
No comments:
Post a Comment