Reputation: 602
I am new to xslt,Below is the xml input
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://xyz.com.zr/l8q/12Q/service/">
<soapenv:Header>
<ser:User>
<!-- comment -->
<Username/>
<password/>
</ser:User>
</soapenv:Header>
<soapenv:Body>
<mainTag>
<abc>1596056</abc>
<asdd>12434F</asdd>
<childtag>
<asdf>1233</asdf>
<qwe>567</qwe>
</childtag>
</mainTag>
</soapenv:Body>
</soapenv:Envelope>
below is the desired output(text) needed
01|1596056|12434F
02|1233| |567|
So in summary, want to achieve desired output, intersted in knowing below details
1) how can i make the text output from xslt.
2) how to make/avoid newline (i.e break).
3) how to generate spaces in text.
below is the logic
01 = this is line number in the text (first line)
1596056 = <abc>
12434F = <asdd>
02 = this is line number in the text (second line)
1233 = <asdf>
567 = <qwe>
Thanks
Upvotes: 0
Views: 85
Reputation: 1067
Your logic is somewhat inconsistent but I'm not going to dwell on that. Instead I've written an xsl that produces the output and answers your aims 1) 2) and 3). I've embedded comments at the relavant code points.
These are basic concepts of xslt, so if you cant follow it I suggest to do some background reading on working with xslt. There are plenty of resources for this.. http://www.w3schools.com springs to mind but of course there will be many more on the web.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<!-- 1) output method is "text" -->
<xsl:output method="text" version="1.0" encoding="UTF-8"/>
<!-- identity transform, apply templates without output -->
<xsl:template match="@*|node()">
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
<!-- matches on soap envolpe body Body for the namespace http://schemas.xmlsoap.org/soap/envelope/ -->
<xsl:template match="s:Body">
<!-- list of tags that you want to count -->
<xsl:apply-templates select="mainTag | mainTag/childtag "/>
</xsl:template>
<xsl:template match="mainTag">
<!-- output context position from within nodeset specified with the apply-templates above-->
<xsl:value-of select="concat('0',position())"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="abc"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="asdd"/>
<!-- 2) new line using entity -->
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="childtag">
<xsl:value-of select="concat('0',position())"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="asdf"/>
<!-- 3) you can include a space within the xsl:text -->
<xsl:text>| |</xsl:text>
<xsl:value-of select="qwe"/>
<xsl:text>|</xsl:text>
<!-- 2) new line using entity -->
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
Upvotes: 0