xml
<block4>
<tag>
<name>50K</name>
<value>
0501/045788775099
Praveen // name will come
MENENDEZ Y PELAYOA CORUNA SPA // address will come
</value>
</tag>
</block4>
i have written a xslt for this above tag but i have facing a problem with replacing remaining length with space the above value you can see in middle line praveen is there let us assume for this xml message praveen we recieved for another message we cam may be recieve Tom but maximum length is 35 so we need to caluclate the string name value remaining length we should replace with SPACE so i dunno how replace a space over there ...
xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:for-each select ="block4/tag[name = '50K']">
<xsl:value-of select="concat(substring(value, 1, 5), ',',substring(substring- before(value,' '),6), ',',substring-after(value,' '))" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
EXpected OUPUT lIKE:
0501/,045788775099,praveen............................MENENDEZ Y PELAYOA CORUNA SPA
where dots represents space dont assume dots
i need space over there assume think praveen is 7 char and remaining 28 char should make space wantedly in xslt
With Apache FOP, in order to output a space like in HTML you would have to insert   .   always worked for me, but you can also try with   to see if it works. <fo:leader> without any attributes will generate an empty line that will fit the whole page width, generating an empty line.
The <xsl:strip-space> element strips white-space-only text nodes in the specified elements. By default, all white-space-only text nodes are preserved. If an element name matches a name test in an <xsl:strip-space> element, it is removed from the set of white-space-preserving element names.
In XML a namespace is a collection of names used for elements and attributes. A URI (usually, a URL) is used to identify a particular collection of names.
The <xsl:text> element is used to write literal text to the output. Tip: This element may contain literal text, entity references, and #PCDATA.
Try using
<xsl:text> </xsl:text>
The space is between those tags.
For more info: XSLT Controlling Whitespace
let us assume for this xml message praveen we recieved for another message we cam may be recieve Tom but maximum length is 35 so we need to caluclate the string name value remaining length we should replace with SPACE so i dunno how replace a space over there ...
Use:
substring(concat($vstr, $vBlanks35), 1, 35)
This evaluates to the result of concatenating $vstr
('Praveen') with $vBlanks35
(35 blanks) and then taking the starting 35 characters.
Here is a complete example:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vstr" select="'Praveen'"/>
<xsl:variable name="vBlanks35" select=
"' '"/>
<xsl:template match="/">
"<xsl:value-of select=
"substring(concat($vstr, $vBlanks35), 1, 35)"/>"
</xsl:template>
</xsl:stylesheet>
when this transformation is applied on any XML document (not used), the wanted, correct result is produced:
"Praveen "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With