I have the following node I need to parse using XSLT 1.0 from xml file
<log>Passed -ID:1 -Log:
Passed -ID:2 -Log:Suite
File/Folder
Failed -ID:3 -Log:Suite
Validate Install Failed
Passed -ID:4 -Log:
</log>
Here is the -ID: -Log:
as you can see can be written on one line or on multiple lines.
In result I would like to get another xml file where the data from node will be parsed. If record with ID was Passed then I need to write “/>.
If record was Failed then I need to write
<testcase name="<ID Name>">
<failure message="<Log Message>"/>
</testcase>
In other words I need to get this xml file.
<xml>
<testcase name="1"/>
<testcase name="2"/>
<testcase name="3">
<failure message="Suite Validate Install Failed"/>
</testcase>
<testcase name="4"/>
</xml>
What do you think can be best way to do this?
The xml file is actually very big and I provided here only one node I need to parse. I’m using xslt because I’m getting other information from other nodes which I also need for result xml files.
Thank you.
The following XSLT demonstrates how to split
logcontent in tokens just usingtokenize(). There are probably better choices with XSLT 2.0 (for examplexsl:analyze-string), but because of usingtokenize()only, this solution is applicable also to XSLT 1.0 extended with EXSLT templates.XSLT 2.0 tested on Saxon-B 9.0.0.2J
The above XSLT applied on the following input:
Produces the following output:
Note that

is due to line-feeds of the source text appearing because we are placing the content inside the attribute value. To get rid of that it would be better to include the message as content of the elementfailure. Anyway the following article deals with tricky spaces.