bigbavarian Posted August 1, 2012 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 Link to comment Share on other sites More sharing options...
boen_robot Posted August 2, 2012 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> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now