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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -