xslt - how to add xsl attribute -
i have xml img tag
<img> source </img> i want generate:
<img src="source.jpg"> i tried that:
<img> <xsl:attribute name="src"> <xsl:text> <xsl:value-of select="node()" />.jpg </xsl:text> </xsl:attribute> </img> but doesng work
the reason why doing not work cannot evaluate xslt expressions inside of <xsl:text> element.
<xsl:text> can contain literal text, entity references, , #pcdata.
if move <xsl:value-of> outside of <xsl:text>, following work:
<img> <xsl:attribute name="src"> <xsl:value-of select="node()" /> <xsl:text>.jpg</xsl:text> </xsl:attribute> </img> however, selecting <xsl:value-of select="node()> <img> in example include carriage returns , whitespace characters inside of <img> element, not want in src attribute value.
that why dimitre novatchev used normalize-space() in answer. applying example above:
<img> <xsl:attribute name="src"> <xsl:value-of select="normalize-space(node())" /> <xsl:text>.jpg</xsl:text> </xsl:attribute> </img> if rid of <xsl:text> fabiano's solution suggests, this:
<img> <xsl:attribute name="src"><xsl:value-of select="normalize-space(node())" />.jpg</xsl:attribute> </img>
Comments
Post a Comment