ChopShop Posted December 9, 2011 Share Posted December 9, 2011 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. Link to comment Share on other sites More sharing options...
dies_felices Posted December 9, 2011 Share Posted December 9, 2011 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> Link to comment Share on other sites More sharing options...
dies_felices Posted December 10, 2011 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> Link to comment Share on other sites More sharing options...
ChopShop Posted December 13, 2011 Author 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. Link to comment Share on other sites More sharing options...
Martin Honnen Posted December 15, 2011 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. Link to comment Share on other sites More sharing options...
ChopShop Posted December 15, 2011 Author Share Posted December 15, 2011 You Rock Martin! Thank you very much! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.