bigbavarian 0 Posted August 1, 2012 Report Share Posted August 1, 2012 Hello everyone, I am new to xsl and trying to adjust an existing template at work. I am trying to change the value of a tag via the xsl. Example: Is the value of the SC_DF_FIELD_2 field in xml is "inactive", I would like to to display as something like "retired". I saw some code that I have been trying to insert into the existsing document but I am unable to get it to work. When I look at the xml, it appears like below. <SC_DF_FIELD_2 display_name="Employee status" element_type="r"><![CDATA[inactive]]></SC_DF_FIELD_2> This was the code I received.<xsl:template match="A1[text() = '0']"><A1>AA</A1></xsl:template> I changed it to read <xsl:template match="SC_DF_FIELD_2[text() = 'inactive']"><SC_DF_FIELD_2>retired</SC_DF_FIELD_2></xsl:template> Is there something else I should be doing? Thanks for taking a look. Stephen Quote Link to post Share on other sites
boen_robot 107 Posted August 2, 2012 Report Share Posted August 2, 2012 Since your source XML uses a CDATA, you may have to compare the whole text contents instead of just text(), i.e. <xsl:template match="SC_DF_FIELD_2[. = 'inactive']"><SC_DF_FIELD_2>retired</SC_DF_FIELD_2></xsl:template> Your XSLT should also contain a template that would define what to do for other nodes. Or at least templates that would eventually use xsl:apply-templates so that your template is matched.If you don't have other templates, and want to preserve all other nodes, you can use a template that just copies the node, and applies the inner templates (which will eventually lead to a match on your other template), like so: <xsl:template match="*|@*|node()"><xsl:copy><xsl:apply-templates/></xsl:copy></xsl:template> 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.