Monday, 14 July 2014

Use xslt to display mutiple attributes with same name



I'm rather new to the world of xml and xslt. What I am wanting to do is use an xslt to return all the error messages generated in an xml file, there are many error messages under each parent.


Here's an example of the XML file:



<progress_file>
<read_leg>
<info>Successfully read face ID 225</info>
<info>successfully read face ID 226</info>
<error>unable to read face ID 227<error>
<error>unable to read face ID 228</error>
</read_leg>
<write_leg>
<info>Successfully created face ID 225</info>
<info>successfully created face ID 226</info>
<error>unable to write face ID 227<error>
<error>unable to write face ID 228</error>
</write_leg>
</progress_file>


The XSLT used is:



<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:template match="/">
<xsl:for-each select="progress/read_leg">
<xsl:value-of select="error"/>
</xsl:for-each>
<xsl:for-each select="progress/write_leg">
<xsl:value-of select="error"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


The output only returns the first value from each area. I gather that this is what the logic implies, i.e. "for each write leg, return the error message" and this doesn't mean it checks if there are multiple cases.


I haven't seen anywhere that has multiple attributes with the same name and I haven't come across and XSL element that can work with this, so I'm a bit stuck. Any suggestions on how this is possible?


One further question, is it possible to get line breaks inbetween the output lines?


Thanks.


No comments:

Post a Comment