Reputation: 235
hi here below i have shown my xml existing a value like three line feed but doubt how to fetch a value based on line feed in xslt logic can any help me
<message>
<block4>
<tag>
<name>57D</name>
<value>BVALESM M0746A
051028GB ES00069074
6A051028 GBES00069</value>
</tag>
</block4>
</message>
here is my xslt which was i was trying but still some issues kindly please suggest me
<xsl:when test="tag[name = '57D'] ">
<xsl:variable name="l" select="substring-before(tag[name = '57D']/value, ' ')"/>
<xsl:variable name="r" select="substring-after(substring-before(tag[name = '57D']/value, ' '), ' ')"/>
<xsl:value-of select="concat(substring(concat($l,' '),1,35),substring(concat($r,' '),1,35))"/>
</xsl:when>
generating output as:
BVALESM M0746A 051028GB ES000690746A051028 GBES00069
it was considering total value after the first clrf so it was not checking logic
required output like
BVALESM M0746A 051028GB ES00069074 6A051028 GBES00069
each line max has to be 35 , it was not every time data should come as 35 for each so if not means we need t insert space
Upvotes: 0
Views: 643
Reputation: 24826
Ok, the actual question is heavily changed in the requirements since its original formulation. Now I'll provide a new answer.
The following transform behaves as follows:
[XSLT 1.0]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="message/block4/tag">
<xsl:variable name="result">
<xsl:call-template name="split-string">
<xsl:with-param name="string" select="value"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$result"/>
</xsl:template>
<xsl:template name="split-string">
<xsl:param name="string"/>
<xsl:variable name="l" select="substring-before($string, '
')"/>
<xsl:variable name="r" select="substring-after($string, '
')"/>
<xsl:choose>
<xsl:when test="$l">
<xsl:variable name="spaces">
<xsl:call-template name="padding">
<xsl:with-param name="times"
select="35 - string-length(normalize-space($l))"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat(normalize-space($l),$spaces)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space($string)" />
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$r">
<xsl:call-template name="split-string">
<xsl:with-param name="string" select="$r" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="padding">
<xsl:param name="times" select="0"/>
<xsl:param name="spaces" select="''"/>
<xsl:choose>
<xsl:when test="$times>0">
<xsl:call-template name="padding">
<xsl:with-param name="times" select="$times - 1"/>
<xsl:with-param name="spaces" select="concat($spaces,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$spaces"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
When applied to the following input:
<message>
<block4>
<tag>
<name>57D</name>
<value>BVALESM M0746A
051028GB ES00069074
6A051028 GBES00069</value>
</tag>
</block4>
</message>
This output is produced:
BVALESM M0746A 051028GB ES00069074 6A051028 GBES00069
Upvotes: 1
Reputation: 7990
there are some options but it heavily depends on your other constraints, mostly related to your xslt processor and its runtime environment:
Upvotes: 0