I'm trying to figure out how to use XSLT Streaming (to reduce memory usage) in a scenario that requires grouping (with an arbitrary number of groups) and summing the group. So far I haven't been able to find any examples. Here's an example XML
<?xml version='1.0' encoding='UTF-8'?>
<Data>
<Entry>
<Genre>Fantasy</Genre>
<Condition>New</Condition>
<Format>Hardback</Format>
<Title>Birds</Title>
<Count>3</Count>
</Entry>
<Entry>
<Genre>Fantasy</Genre>
<Condition>New</Condition>
<Format>Hardback</Format>
<Title>Cats</Title>
<Count>2</Count>
</Entry>
<Entry>
<Genre>Non-Fiction</Genre>
<Condition>New</Condition>
<Format>Paperback</Format>
<Title>Dogs</Title>
<Count>4</Count>
</Entry>
</Data>
In XSLT 2.0 I would use this to group by Genre, Condition and Format and Sum the counts.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" />
<xsl:template match="/">
<xsl:call-template name="body"/>
</xsl:template>
<xsl:template name="body">
<xsl:for-each-group select="Data/Entry" group-by="concat(Genre,Condition,Format)">
<xsl:value-of select="Genre"/>
<xsl:value-of select="Condition"/>
<xsl:value-of select="Format"/>
<xsl:value-of select="sum(current-group()/Count)"/>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
For output I would get two lines, a sum of 5 for Fantasy, New, Hardback and a sum of 4 for Non-Fiction, New, Paperback.
Obviously this won't work with Streaming because the sum accesses the whole group. I think I need to iterate through the document twice. The first time I could build a map of the groups (creating a new group if one doesn't exist yet). The second time The problem is I also need an accumulator for each group with a rule that matches the group, and it doesn't seem you can create dynamic accumulators.
Is there a way to create accumulators on the fly? Is there another/easier way to do this with Streaming?
To be able to use streamed grouping with XSLT 3.0 one option that I see is to first transform the element based data you have into attribute based data using a stylesheet like
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
version="3.0">
<xsl:mode streamable="yes" on-no-match="shallow-copy"/>
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Entry/*">
<xsl:attribute name="{name()}" namespace="{namespace-uri()}" select="."/>
</xsl:template>
</xsl:stylesheet>
then you can perfectly used streamed grouping (as far as a streamed group-by is possible at all, as far as I understand there will be some buffering necessary) as follows:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
version="3.0">
<xsl:mode streamable="yes"/>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:fork>
<xsl:for-each-group select="Data/Entry" composite="yes" group-by="#Genre, #Condition, #Format">
<xsl:value-of select="current-grouping-key(), sum(current-group()/#Count)"/>
<xsl:text>
</xsl:text>
</xsl:for-each-group>
</xsl:fork>
</xsl:template>
</xsl:stylesheet>
I don't know whether first creating an attribute centric document is an option but I think it is better to share suggestions with code in an answer instead of trying to put them into a comment. And the answer in XSLT Streaming Chained Transform shows how to use Saxon 9 with Java or Scala to chain two streaming transformations without the need to write a temporary output file for the first transformation step.
As for doing it with copy-of on the original input format, Saxon 9.7 EE assesses the following as streamable and executes it with the right result:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs math"
version="3.0">
<xsl:mode streamable="yes"/>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each-group select="copy-of(Data/Entry)" composite="yes"
group-by="Genre, Condition, Format">
<xsl:value-of select="current-grouping-key(), sum(current-group()/Count)"/>
<xsl:text>
</xsl:text>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
I am not sure it consumes less memory however than normal, tree based grouping. Perhaps you can measure with your real input data.
As a third alternative, to use a map as you seemed to want to do, here is an xsl:iterate example that iterates through the Entry elements, collecting the accumulated Count value in a map:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:map="http://www.w3.org/2005/xpath-functions/map" exclude-result-prefixes="xs math map"
version="3.0">
<xsl:mode streamable="yes"/>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:iterate select="Data/Entry">
<xsl:param name="groups" as="map(xs:string, xs:integer)" select="map{}"/>
<xsl:on-completion>
<xsl:value-of select="map:keys($groups)!(. || ' ' || $groups(.))" separator="
"/>
</xsl:on-completion>
<xsl:variable name="current-entry" select="copy-of()"/>
<xsl:variable name="key"
select="string-join($current-entry/(Genre, Condition, Format), '|')"/>
<xsl:next-iteration>
<xsl:with-param name="groups"
select="
if (map:contains($groups, $key)) then
map:put($groups, $key, map:get($groups, $key) + xs:integer($current-entry/Count))
else
map:put($groups, $key, xs:integer($current-entry/Count))"
/>
</xsl:next-iteration>
</xsl:iterate>
</xsl:template>
</xsl:stylesheet>
Related
I am working on transforming a huge set of data (~1000k records) using XSLT 3.0. I am getting Java memory heap errors in my ERP system (Workday) since the input XML message is very big. I tried streaming xslt only, but couldn't make it work. Can someone please assist me in transforming the data memory efficient way.
<?xml version="1.0" encoding="UTF-8"?>
<a:Report_Data xmlns:a="urn:com.workday.report/INT_Currency_Conversion_Rates_-_Monthly_Source">
<a:Report_Entry>
<a:Source_Currency>USD</a:Source_Currency>
<a:Target_Currency>INR</a:Target_Currency>
<a:Currency_Rate>76.33</a:Currency_Rate>
</a:Report_Entry>
<a:Report_Entry>
<a:Source_Currency>USD</a:Source_Currency>
<a:Target_Currency>CHN</a:Target_Currency>
<a:Currency_Rate>16.33</a:Currency_Rate>
</a:Report_Entry>
<a:Report_Entry>
<a:Source_Currency>CHN</a:Source_Currency>
<a:Target_Currency>INR</a:Target_Currency>
<a:Currency_Rate>26.33</a:Currency_Rate>
</a:Report_Entry>
</a:Report_Data>
XSLT code that I have tried:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:a="urn:com.workday.report/INT_Currency_Conversion_Rates_-_Monthly_Source"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
version="3.0">
<xsl:output method="xml" indent="no" omit-xml-declaration="yes" />
<xsl:mode streamable="yes" on-no-match="shallow-skip" />
<xsl:template match="a:Report_Data">
<RTMap>
<xsl:fork>
<xsl:for-each-group select="a:Report_Entry/copy-of()" group-by="a:Source_Currency">
<xsl:for-each-group select="current-group()" group-by="a:Target_Currency">
<Row>
<Map_Rate><xsl:value-of select="avg(current-group()/a:Currency_Rate)"/></Map_Rate>
<Map_From_Currency><xsl:value-of select="a:Source_Currency"/></Map_From_Currency>
<Map_Target_Currency><xsl:value-of select="a:Target_Currency"/></Map_Target_Currency>
</Row>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:fork>
</RTMap>
</xsl:template>
</xsl:stylesheet>
Thank you,
Jay
In XSLT 3 you can use a composite key and if you use copy-of() you don't need the xsl:fork:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.workday.report/INT_Currency_Conversion_Rates_-_Monthly_Source"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:template match="Report_Data">
<RTMap>
<xsl:for-each-group select="Report_Entry!copy-of()" composite="yes" group-by="Source_Currency, Target_Currency ">
<Row>
<Map_Rate>{avg(current-group()/Currency_Rate)}</Map_Rate>
<Map_From_Currency>{current-grouping-key()[1]}</Map_From_Currency>
<Map_Target_Currency>{current-grouping-key()[2]}</Map_Target_Currency>
</Row>
</xsl:for-each-group>
</RTMap>
</xsl:template>
<xsl:output method="xml" indent="yes"/>
<xsl:mode on-no-match="shallow-skip" streamable="yes"/>
</xsl:stylesheet>
But in the end any group-by needs to buffer groups as you don't know whether the last Report_Entry might belong into the first group so any grouping of that input based on those keys will consume memory. Streamed grouping with a low memory consumption works if you use group-starting-with or group-adjacent, if the input data and the requirements allow that, but group-by is always going to buffer groups.
I receive a sequence of Codes of which I do not know which ones are "wildcard" codes and which are complete codes. In my example below Code '1234' is a "wildcard" code and Code '5678' is a complete code. So, I need the xslt that will return all Procedures having a Code that starts with 1234 or is equal to Code 5678. I know the starts-with xslt function cannot be applied to a sequence. I have tried many variations of for-each, all to no avail. Any suggestions?
Sorry if I was not clear, I do not know which Codes are wildcard and which are complete. A "starts-with" function would match Procedure codes starting with a specified code and also Procedure codes that exactly match a specified code. The Codes I provided were an example of what I am receiving, 1234 and 5678 can both be wildcards or neither, etc...
Codes XML:
<Codes>
<Code>1234</Code>
<Code>5678</Code>
</Codes>
Procedures XML:
<Procedures>
<Procedure>
<Code>12345678</Code>
</Procedure>
<Procedure>
<Code>5678</Code>
</Procedure>
<Procedure>
<Code>91011</Code>
</Procedure>
<Procedure>
<Code>12348765</Code>
</Procedure>
</Procedures>
What I need to return is the following:
<Procedures>
<Procedure>
<Code>12345678</Code>
</Procedure>
<Procedure>
<Code>5678</Code>
</Procedure>
<Procedure>
<Code>12348765</Code>
</Procedure>
</Procedures>
I am going to ignore the confusing distinction between complete codes and "wildcard" codes, and concentrate on the underlying question, which is: how to apply the starts-with() function when you have multiple starting strings to check against.
IOW, we are looking for a way to select Procedure nodes whose Code starts with any of the codes listed in Codes.xml.
This can be done simply by reversing the point of view:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:param name="path-to-codes" select="'Codes.xml'"/>
<xsl:template match="/Procedures">
<xsl:copy>
<xsl:for-each select="Procedure">
<xsl:variable name="current-code" select="Code" />
<xsl:if test="document($path-to-codes)/Codes/Code[starts-with($current-code, .)]">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I'm not sure I understand exactly you are looking for, but I think this should work.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="inputCodes">
<Codes>
<Code>1234</Code>
<Code>5678</Code>
</Codes>
</xsl:variable>
<xsl:variable name="wildcard" select="$inputCodes/Codes/Code[1]"/>
<xsl:variable name="complete" select="$inputCodes/Codes/Code[2]"/>
<xsl:template match="Procedure[not(Code=$complete or starts-with(Code,$wildcard))]"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
See it working here : https://xsltfiddle.liberty-development.net/a9HjZE
One way to realize this is this XSLT-2.0 stylesheet (The first file with the restrictions is named Codes.xml):
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:variable name="wildcard" select="doc('Codes.xml')/Codes/Code[1]" />
<xsl:variable name="complete" select="doc('Codes.xml')/Codes/Code[2]" />
<xsl:strip-space elements="*" />
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
<xsl:template match="Procedure" />
<xsl:template match="Procedure[starts-with(Code,$wildcard) or Code=$complete]">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
Its output is as expected:
<Procedures>
<Procedure>
<Code>12345678</Code>
</Procedure>
<Procedure>
<Code>5678</Code>
</Procedure>
<Procedure>
<Code>12348765</Code>
</Procedure>
</Procedures>
The above stylesheet defines two variables for "wildcard" and "complete" string values. Then it copies all other elements with the identity template and omits all Procedure elements except for the ones acknowleged in the last template which realize the wanted conditions.
I would like to be able to select one element from group of duplicates (done with Muenchian grouping) having certain sub-element. My XML looks like this:
<waybill>
<shipment>
<parcel>
<sscc>SSCC1</sscc>
<consignee>Receiver1</consignee>
<date>Date1</date>
<status>Status1</status>
</parcel>
<parcel>
<sscc>SSCC2</sscc>
<consignee>Receiver2</consignee>
<attention>Note2</attention>
</parcel>
<parcel>
<sscc>SSCC3</sscc>
<consignee>Receiver3</consignee>
</parcel>
<parcel>
<sscc>SSCC4</sscc>
<consignee>Receiver4</consignee>
</parcel>
<parcel>
<sscc>SSCC1</sscc>
<consignee>Receiver1</consignee>
<attention>Note1</attention>
<date>Date2</date>
<status>Status2</status>
</parcel>
<parcel>
<sscc>SSCC3</sscc>
<consignee>Receiver3</consignee>
<attention>Note3</attention>
</parcel>
</shipment>
</waybill>
and my XSLT looks like this:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0">
<xsl:output method="text" version="1.0" encoding="ISO-8859-1" indent="yes"/>
<xsl:key name="ean" match="parcel" use="sscc"/>
<xsl:template match="/">
<xsl:for-each select="/waybill/shipment/parcel[generate-id()=generate-id(key('ean',sscc))]">
<xsl:value-of select="current()/sscc"/>
<xsl:text>§</xsl:text>
<xsl:value-of select="current()/consignee"/>
<xsl:text>§</xsl:text>
<xsl:value-of select="current()/attention"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The output now looks like this:
SSCC1§Receiver1§
SSCC2§Receiver2§Note2
SSCC3§Receiver3§
SSCC4§Receiver4§
so my XSLT will now pick the first hit from the grouped elements and what I would like to have as a the result is:
SSCC1§Receiver1§Note1
SSCC2§Receiver2§Note2
SSCC3§Receiver3§Note3
SSCC4§Receiver4§
So the XSLT should find those duplicates from group with has the most data. Not first or last one, but the one with certain sub-element (or in my final case: sub-sub-element)
In this case not all of the element has the sub-element (here SSCC4) and those should be used with the data they have (should not be ignored).
What is the correct way to find the "best" element from the grouped similar elements?
Any help is highly appreciated :)
You can navigate from the key(), like this:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0">
<xsl:output method="text" version="1.0" encoding="ISO-8859-1" indent="yes"/>
<xsl:key name="ean" match="parcel" use="sscc"/>
<xsl:template match="/">
<xsl:for-each select="/waybill/shipment/parcel[generate-id()=generate-id(key('ean',sscc))]">
<xsl:variable name="group" select="key('ean',sscc)" />
<xsl:value-of select="sscc"/>
<xsl:text>§</xsl:text>
<xsl:value-of select="$group/consignee"/>
<xsl:text>§</xsl:text>
<xsl:value-of select="$group/attention"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
key('ean',sscc) would select all <parcel> elements of the current group and key('ean',sscc)/attention all <attention> elements beneath them.
In XSLT 2.0+ you can also use <xsl:for-each-group> and the current-group() function for the same effect.
Using key('ean',sscc)/attention in a <xsl:value-of> would only print the value of the first match, which is what your intention seems to be anyway.
Using current() explicitly like you did is not really necessary. current() is meant to be used inside XPath predicates, in a normal select expression it doesn't add any value.
Seeking advice on how to calculate the lowerCorner and upperCorner in GML Envelope given an array (coordinates) in the XML. Note I have reduced the list of coordinates significantly to keep short.
Aware I need to iterate the <coordinates> element but unsure most efficient way to calculate the lowerCorner and upperCorner pairs to eventually map into the GML Envelope.
XML Sample
<?xml version="1.0" encoding="UTF-8"?>
<Extract>
<n1:XMLExtract xmlns:n1="urn:com:aaa">
<regionId>4671</regionId>
<coordinates>151.344553 -33.4123250000193, 151.346606 -33.4126370000193, 151.347188 -33.4127280000193, 151.347707 -33.4127990000193, 151.347858 -33.4121160000193, 151.34931 -33.4123270000192, 151.349253 -33.4125910000192, 151.349693 -33.4126610000193, 151.34963 -33.4129810000192, 151.351338 -33.4132280000193, 151.351393 -33.4129550000193, 151.352038 -33.4130480000192, 151.352169 -33.4128100000193, 151.352355 -33.4128370000193, 151.35249 -33.4128910000193, 151.352585 -33.4129170000193, 151.352913 -33.4130080000193, 151.35294 -33.4131310000193, 151.355307 -33.4134860000192, 151.355315 -33.4134470000193, 151.355764 -33.4135020000193, 151.355757 -33.4135590000193, 151.356196 -33.4136240000192, 151.356229 -33.4134890000192, 151.356342 -33.4136260000193, 151.358407 -33.4139280000192, 151.358335 -33.4142510000192, 151.358465 -33.4143660000193, 151.359572 -33.4145260000194, 151.359936 -33.4144860000193, 151.360146 -33.4146080000193, 151.360627 -33.4146790000192, 151.360619 -33.4146980000193, 151.362603 -33.4149980000193, 151.362996 -33.4150940000193, 151.363655 -33.4158080000193, 151.364236 -33.4161380000194, 151.365691 -33.4163460000193, 151.366212 -33.4164920000193, 151.367333 -33.4170870000193, 151.368456 -33.4180250000193, 151.368481 -33.4180200000193, 151.368888 -33.4183130000193, 151.371305 -33.4187840000193, 151.373106 -33.4187890000193, 151.374004 -33.4189970000194, 151.374994 -33.4194460000193, 151.376513 -33.4199650000193, 151.378063 -33.4197680000193, 151.379519 -33.4185780000193, 151.383555 -33.4161210000193, 151.393929 -33.4059400000192, 151.396063 -33.4062720000193, 151.396727 -33.4051740000192, 151.39785 -33.4032380000193, 151.397122 -33.4027200000192, 151.396761 -33.4022700000193, 151.396541 -33.4008350000192, 151.397496 -33.3995910000192, 151.397788 -33.3990280000193, 151.397788 -33.3990100000192, 151.397773 -33.3990000000192, </coordinates>
<interactionId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="1" />
<interactionTypeId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="1" />
<refNumber/>
<incidentNumber/>
<payloadId>20002065</payloadId>
<filename/>
<url/>
</n1:XMLExtract>
</Extract>
Desired output as follows:
<gml:boundedBy>
<gml:Envelope srsDimension="2" srsName="EPSG:4283">
<gml:lowerCorner>-30.511985 151.63592</gml:lowerCorner>
<gml:upperCorner>-30.49207 151.669169</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
Assuming you want to find the coordinates of the rectangle bounding your polygon, and assuming your processor supports the EXSLT extension functions str:split(), math:min() and math:max() (IOW, you are using either libxslt or Xalan), you could do something like:
XSLT 1.0 + EXSLT
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:n1="urn:com:aaa"
xmlns:exsl="http://exslt.org/common"
xmlns:math="http://exslt.org/math"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="exsl math str"
exclude-result-prefixes="n1">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/Extract">
<xsl:variable name="vertices-rtl">
<xsl:for-each select="str:split(n1:XMLExtract/coordinates, ', ')">
<v x="{substring-before(., ' ')}" y="{substring-after(., ' ')}"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="vertices" select="exsl:node-set($vertices-rtl)/v" />
<output>
<lowerLeft>
<xsl:value-of select="math:min($vertices/#x)" />
<xsl:text> </xsl:text>
<xsl:value-of select="math:min($vertices/#y)" />
</lowerLeft>
<upperRight>
<xsl:value-of select="math:max($vertices/#x)" />
<xsl:text> </xsl:text>
<xsl:value-of select="math:max($vertices/#y)" />
</upperRight>
</output>
</xsl:template>
</xsl:stylesheet>
Applied to your example input, the result will be:
<?xml version="1.0" encoding="UTF-8"?>
<output>
<lowerLeft>151.344553 -33.4199650000193</lowerLeft>
<upperRight>151.39785 -33.3990000000192</upperRight>
</output>
I have the following code (eg):
<response>
<parameter>
<cottage>
<cot>
<res>
<hab desc="Lakeside">
<reg cod="OB" prr="600.84>
<lwz>TR#2#AB#200.26#0#QB#OK#20120829#20120830#EU#3-0#</lwz>
<lwz>TR#2#AB#200.26#0#QB#OK#20120830#20120831#EU#3-0#</lwz>
<lwz>TR#2#AB#200.26#0#QB#OK#20120831#20120901#EU#3-0#</lwz>
I need to create a concatenated string that includes the whole of the first 'lwz' line and then the price (200.26, but it can be different in each line) for each corresponding line.
So the output, separating each line with | would be:
TR#2#AB#200.26#0#QB#OK#20120829#20120830#EU#3-0#|200.26|200.26
Thanks
This XSLT 1.0 transformation:
<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="lwz[1]">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="lwz[position() >1]">
<xsl:value-of select=
"concat('
',
substring-before(substring-after(substring-after(substring-after(.,'#'),'#'),'#'),'#')
)
"/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
when applied on the provided text (converted to a well-formed XML document !!!):
<response>
<parameter>
<cottage>
<cot>
<res>
<hab desc="Lakeside">
<reg cod="OB" prr="600.84">
<lwz>TR#2#AB#200.26#0#QB#OK#20120829#20120830#EU#3-0#</lwz>
<lwz>TR#2#AB#200.26#0#QB#OK#20120830#20120831#EU#3-0#</lwz>
<lwz>TR#2#AB#200.26#0#QB#OK#20120831#20120901#EU#3-0#</lwz>
</reg>
</hab>
</res>
</cot>
</cottage>
</parameter>
</response>
produces the wanted, correct result:
TR#2#AB#200.26#0#QB#OK#20120829#20120830#EU#3-0#
200.26
200.26
II XSLT 2.0 solution:
This transformation:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="lwz[1]">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="lwz[position() >1]">
<xsl:value-of select=
"concat('
', tokenize(.,'#')[4])"/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
when applied on the above XML document, again produces the wanted, correct result. Note the use of the standard XPath 2.0 function tokenize():
TR#2#AB#200.26#0#QB#OK#20120829#20120830#EU#3-0#
200.26
200.26
You can use the XPath substring function to select substrings from your lwz node data. You don't really give much more detail about your problem, if you want a more detailed answer, perhaps provide the full XML document and your best-guess XSLT