Hi, I'm having trouble with a simple transformation.
Here is my XML:
I want to extract the keys, and wrap the text node in CDATA like this:
But getting the CDATA tags in the output is proving difficult. Here is my XSL:
What I get is this:
I tried adding cdata-section-elements="key" to my output tag, but that didn't seem to work. Anyone see what I'm missing to ensure the text node has a cdata section? Also, is it possible to get each key on one line like in my example?
Thanks,
Mike
Here is my XML:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<translationSet>
<key name="SMCAM1744_TITLE" translator="" translationDate="">
<comment/>
<contextImagePath/>
<text>Camera 1744</text>
</key>
<key name="SMCAM1762_TITLE" translator="" translationDate="">
<comment/>
<contextImagePath/>
<text>Camera 1762</text>
</key>
<key name="SMCAM1764_TITLE" translator="" translationDate="">
<comment/>
<contextImagePath/>
<text>Camera 1764</text>
</key>
</translationSet>
I want to extract the keys, and wrap the text node in CDATA like this:
Code:
<key name="SMCAM1744_TITLE"><text><![CDATA[Camera 1744]]></text></key>
<key name="SMCAM1762_TITLE"><text><![CDATA[Camera 1762]]></text></key>
<key name="SMCAM1764_TITLE"><text><![CDATA[Camera 1764]]></text></key>
But getting the CDATA tags in the output is proving difficult. Here is my XSL:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] cdata-section-elements="key text">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="translationSet/key"/>
</xsl:template>
<xsl:template match="translationSet/key">
<xsl:element name="key">
<xsl:attribute name="name">
<xsl:value-of select="@name" />
</xsl:attribute>
<xsl:copy-of select="text" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
What I get is this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<key name="SMCAM1744_TITLE">
<text>Camera 1744</text>
</key><key name="SMCAM1762_TITLE">
<text>Camera 1762</text>
</key><key name="SMCAM1764_TITLE">
<text>Camera 1764</text>
</key>
I tried adding cdata-section-elements="key" to my output tag, but that didn't seem to work. Anyone see what I'm missing to ensure the text node has a cdata section? Also, is it possible to get each key on one line like in my example?
Thanks,
Mike