Forum Moderators: open

Message Too Old, No Replies

XSL string manipulation question

Xsl

         

slow

11:43 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



Can someone please help me with following xsl transformation from a given xml.

xml looks like..

<array>
<month name="MONTH_NAME"
pattern="January(1) February(2) March(3) April(4) May(5) June(6) July(7) August(8) September(9) October(10) November(11) December(12)"
help="Month of the year"/>
</array>

I would like an html table like.

Month Value
January 1
February 2
..
..
December 12

Thanks much!

cmarshall

12:21 am on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you at liberty to change the XML? That structure is not so good for XSLT (It isn't particularly good XML either). You are almost better off using PHP to parse it. It can be done with XSLT, but that would be a bit "kludgy."

A better pattern would be:

<array name="MONTH_NAME">
<array_help>Month of the year</array_help>
<array_values>
<array_value value="1">January</array_value>
<array_value value="2">February</array_value>
<array_value value="3">March</array_value>
<array_value value="4">April</array_value>
<array_value value="5">May</array_value>
<array_value value="6">June</array_value>
<array_value value="7">July</array_value>
<array_value value="8">August</array_value>
<array_value value="9">September</array_value>
<array_value value="10">October</array_value>
<array_value value="11">November</array_value>
<array_value value="12">December</array_value>
</array_values>
</array>

slow

1:32 am on Sep 5, 2007 (gmt 0)

10+ Year Member



Unfortunately this xml is common between multiple components and I do not have the liberty to change it. If you or someone could help me in general direction or some code example, you shall make my day.

cmarshall

2:36 am on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, welcome to WebmasterWorld!

You will need to use XPath [w3schools.com] to do most of the parsing. The function you will probably need will be here [w3schools.com].

XSLT will get you on the green, but you won't be able to use it to sink your putt.

However, XPath 1.0 completely stinks at string parsing. I mean really bad. If you will be using PHP XSLTProcessor [us2.php.net], you need to keep to XPath 1.0 [w3.org] functions. You are better off doing a PHP callout [us2.php.net], or even using PHP DOMDocuments [us2.php.net].

Whomever designed that XML didn't really understand how to use XML properly, so they really limited your options.