How to remove the space inside the <xsl: attribute> tag?

In the XSLT stylesheet, how can I remove leading and trailing spaces inside the <xsl:attribute> ?

For example, the following stylesheet:

 <xsl:template match="/"> <xsl:element name="myelement"> <xsl:attribute name="myattribute"> attribute value </xsl:attribute> </xsl:element> </xsl:template> 

outputs:

 <myelement myattribute="&#10; attribute value&#10; "/> 

while I would like him to output:

 <myelement myattribute="attribute value"/> 

Is there any way to do this besides collapsing the start and end <xsl:attribute> tags on the same line?

Because if the attribute value is not a simple line of text, but the result of some complicated calculation (for example, using or tags), then folding all the code in one line to avoid leading and trailing spaces will lead to a terribly ugly style sheet.

+6
source share
1 answer

You can wrap the text xsl: text or xsl: value-of:

 <xsl:template match="/"> <xsl:element name="myelement"> <xsl:attribute name="myattribute"> <xsl:text>attribute value</xsl:text> </xsl:attribute> </xsl:element> </xsl:template> 

or

 <xsl:template match="/"> <xsl:element name="myelement"> <xsl:attribute name="myattribute"> <xsl:value-of select="'attribute value'"/> </xsl:attribute> </xsl:element> </xsl:template> 

Is this helpful to you? Otherwise, please explain your problem in using one line.

Please pay attention to the comment of Michael Kay, this explains the problem to the point!

+6
source

Source: https://habr.com/ru/post/954854/


All Articles