[Home] [By Thread] [By Date] [Recent Entries]
True, even I felt that the explanation of my problem was a bit
convoluted. I'll try and simply put across what it is that I'm trying to
achieve here [though the scope of the whole problem is a bit too vast]:
Considering that I have an input XML like: <person> <name>ABC</name> <age>24</age> <city>Bangalore</city> </person> This XML data needs to be converted into an HTML-like snippet which would then be used to construct a JSON object. I'm not quite sure whether you've worked with JSON before, but it is simply a name-value pair construct in JavaScript. Each value needs to be enclosed within double-quotes ("). So basically, whatever value has to go in, CANNOT contain any ", or all " need to be escaped (\"). So coming back to the XML above, the XSLT should generate a HTML-like snippet shown below: <table width=\"100%\">
<tr>
<td width=\"150\">
Name :
<input type=\"text\" value=\"[name_node_value]\"/>
</td>
</tr>
<tr>
<td width=\"150\">
Age :
<input type=\"text\" value=\"[age_node_value]\"/>
</td>
</tr>
<tr>
<td width=\"150\">
City :
<input type=\"text\" value=\"[city_node_value]\"/>
</td>
</tr>
</table>This text can then be set as a value in the JSON construct. The alogrithm I tried to adopt was: 1. Process i/p XML and store transformed text in a variable. 2. Use the text within this variable and use the in-built XSLT function replace, to substitute all occurrences of " with \" I hope this would help you understand my problem a bit better. Thanks. Michael Kay wrote: You're talking about "tags". Tags don't exist in the data manipulated by XSLT. XSLT only manipulates nodes in a tree. The way to solve your problem is to use XSLT the way it was designed to be used: forget about CDATA and tags, and think about element nodes.
|

Cart



