i have simple xml document i'm trying replace element based on element's value.
<document> <meta> <wk_abc> ucm:source1 </wk_abc> <wk_def> other text </wk_def> <wk_abc> ucm:source2 </wk_abc> </meta> <content> lorem ipsum </content> </document> my xsl this:
<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()" /> </xsl:copy> </xsl:template> <xsl:template match="wk_abc"> <xsl:if test=".='ucm:source1'"> <bob>bob</bob> </xsl:if> </xsl:template> but keeps failing if condition. , skipping on replacement element. why test failing?
this because there whitespace either side of 'ucm:source1' in node.
try changing xsl:if condition remove white-space before doing check:
<xsl:if test="normalize-space()='ucm:source1'"> note more trim white space. if text ucm:source1 ucmsource2 example, whitepsaces in middle merged 1 single space, normalize-space return ucm:source1 ucmsource2
Comments
Post a Comment