I have a little question about xsl. I tried to solve it myself, but I can't get it done. Basically all I want is linebreaks.
My xsl looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://ift.tt/tCZ8VR" version="2.0"
xmlns:ex="example">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[local-name() = 'table']"/>
<xsl:template match="*[local-name() = 'text']">
<xsl:copy>
<xsl:attribute name="value">
<xsl:apply-templates/>
</xsl:attribute>
</xsl:copy>
</xsl:template>
<xsl:template match="*[local-name() = 'b' or local-name() = 'i']">
<xsl:value-of select="concat('[',local-name(),']')"/>
<xsl:apply-templates/>
<xsl:value-of select="concat('[/',local-name(),']')"/>
</xsl:template>
<xsl:template match="@value">
<xsl:attribute name="value">
<xsl:value-of select="translate(.,'
','
')"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="@href"/>
</xsl:transform>
What I found out, is that I could use something like this:
<xsl:if test="not(position()=last())">
<xsl:text>
</xsl:text>
</xsl:if>
But I don't know how to combine it with my xsl. I tried to just put it in the <xsl:attribute name="value"> xsl:copy part. It inserts a linebreak, but at the wrong place. Also I cant put it inside of xsl:apply-templates.
Would someone be so kind to tell me, where I have to add this code?
A xml example(how it looks originally, with only the "indent" transformation):
<text>This is some text and here
is a linebreak</text>
Should look like:
<text value="This is some text and here
is a linebreak"/>
Currently looks like:
<text value="This is some text and here
is a linebreak"/>
Thank you in advance!
No comments:
Post a Comment