Hi guys,
I'm stuck with something which is probably quite simple to resolve but don't have a clue.
My XML data is as follows :-
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="GetTicketCategories.xsl"?>
<ArrayOfCategory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://test.com/test/">
<Category>
<Name>Benefits</Name>
<Count>29</Count>
</Category>
<Category>
<Name>Building Control</Name>
<Count>4</Count>
</Category>
</ArrayOfCategory>
XSL file :-
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="Category">
<xsl:value-of select="Name"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="Count"/>
<xsl:text>, </xsl:text>
</xsl:template>
</xsl:stylesheet>
The output is :-
Benefits29Building Control4
There seems to be an issue with the top element where it doesn't like its formatting e.g. <ArrayOfCategory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ctronix.com/smartticketservice/">
I'm not in a position to change the xml but if I simplify the code it works as below :-
Changed XML :-
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="GetTicketCategories.xsl"?>
<ArrayOfCategory>
<Category>
<Name>Benefits</Name>
<Count>29</Count>
</Category>
<Category>
<Name>Building Control</Name>
<Count>4</Count>
</Category>
</ArrayOfCategory>
XSL:-
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="ArrayOfCategory/Category">
<xsl:value-of select="Name"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="Count"/>
<xsl:text>, </xsl:text>
</xsl:template>
</xsl:stylesheet>
Correct Output:-
Benefits, 29, Building Control, 4,
So how do I get the required output using the existing XML file? I don't know how to use
<ArrayOfCategory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ctronix.com/smartticketservice/">
in the template match section.
I must confess I'm a complete beginner; any help would be very much appreciated.
Cheers
Rich