ChopShop 0 Posted December 9, 2011 Report Share Posted December 9, 2011 (edited) Hello, I am currently needing an XSLT to take an XML file and add quote marks around each string. Does anyone know how to add quote marks around each string? I can't seem to get this to work. Below are samples of the XML that I am dealing with... Example 1: <resources><string-array name="exercise_intensities"><item>None</item><item>Low</item><item>Medium</item><item>High</item></string-array></resources> Example 2: <resources><string name="hello">Hello World!</string><string name="app_name">Test App</string><string name="range_separator">-</string><string name="comma_separator">,</string><string name="no">No</string></resources> So, in Example 1, I need to output an XML file that looks like this: <resources><string-array name="exercise_intensities"><item>"None"</item><item>"Low"</item><item>"Medium"</item><item>"High"</item></string-array></resources> Any help would be greatly appreciated. Edited December 15, 2011 by ChopShop Quote Link to post Share on other sites
dies_felices 0 Posted December 9, 2011 Report Share Posted December 9, 2011 (edited) Hi. There are probably better ways to do it. I hope this helps. I'm assuming the XML will look something like this to allow many strings:- <strings><string>Walking Dead</string></strings> <?xml version = '1.0' encoding = 'ISO-8859-1'?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="xml"/><xsl:template match="/"><xsl:text><strings></xsl:text><xsl:apply-templates select="strings/string"/><xsl:text></strings></xsl:text></xsl:template> <xsl:template match="string"><xsl:text><string></xsl:text>"<xsl:value-of select="text()"/>"<xsl:text></string></xsl:text></xsl:template></xsl:stylesheet> Edited December 9, 2011 by dies_felices Quote Link to post Share on other sites
dies_felices 0 Posted December 10, 2011 Report Share Posted December 10, 2011 Hi. Alternatively, <?xml version = '1.0' encoding = 'ISO-8859-1'?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="xml"/><xsl:template match="/"><strings><xsl:apply-templates select="AnswerSet/Answer"/></strings></xsl:template><xsl:template match="Answer"><string>"<xsl:value-of select="text()"/>"</string></xsl:template></xsl:stylesheet> Quote Link to post Share on other sites
ChopShop 0 Posted December 13, 2011 Author Report Share Posted December 13, 2011 Thanks for replying. I can't seem to get this to work. Below are samples of the XML that I am dealing with... Example 1: <resources><string-array name="exercise_intensities"><item>None</item><item>Low</item><item>Medium</item><item>High</item></string-array></resources> Example 2: <resources><string name="hello">Hello World!</string><string name="app_name">Test App</string><string name="range_separator">-</string><string name="comma_separator">,</string><string name="no">No</string></resources> So, in Example 1, I need to output an XML file that looks like this: <resources><string-array name="exercise_intensities"><item>"None"</item><item>"Low"</item><item>"Medium"</item><item>"High"</item></string-array></resources> Any help would be greatly appreciated. Quote Link to post Share on other sites
Martin Honnen 16 Posted December 15, 2011 Report Share Posted December 15, 2011 Here is a code sample: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy></xsl:template><xsl:template match="*[not(*)]"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:text>"</xsl:text> <xsl:apply-templates/> <xsl:text>"</xsl:text> </xsl:copy></xsl:template></xsl:stylesheet> It copies everything from the input to the output with the exception of elements not having any child elements, there it wraps any content in quotes. 1 Quote Link to post Share on other sites
ChopShop 0 Posted December 15, 2011 Author Report Share Posted December 15, 2011 You Rock Martin! Thank you very much! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.