msxsl - How to only convert an XML file's attribute using XSLT, and leave the other content? -


I have an XML file, and now I want to use xslt in transformer, keep all the elements and attributes, But if it happened with the value starting with "SQL:", then execute SQL and replace the attribute value with the solution SQL (this includes. I have now allocated this issue: the current node type is special , And how to replace the attribute value, I base the base on the Visual Studio default template:

Example xml file (actually contains several elements):

  & Lt; DM & gt; & lt; DV id = "SQL: Choose something from db" & gt; & lt; sample help = "SQL: select something from db" & gt; & lt; / sample & gt; & Lt; / DV & gt; & lt; DV id = "SQL: Choose something from db" & gt; & lt; sample help = "SQL: select something from db" & gt; & lt; / sample & gt; & Lt; / DV & gt; & lt; / d & Gt;  

default xslt:

  & lt ;? Xml version = "1.0" encoding = "UTF -8"? & Gt; & Lt; Xsl: = "1.0" on stylesheet worm xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" xmlns: msxsl = "vase: schema-microsoft-com: xslt" out-result-prefix = "Msaxl" xmlns: ms = "vase: schema-microsoft-com: xslt" & gt; & Lt; Xsl: output method = "xml" indent = "yes" /> & Lt; Xsl: template match = "@ * | node ()" & gt; & Lt; XSL: Copy & gt; & Lt; Xsl: apply-select template = "@ * | node ()" /> & Lt; / XSL: Copy & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;  

This stylesheet:

  & lt; Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" & gt; & Lt; Xsl: template match = "@ * | node ()" & gt; & Lt; XSL: Copy & gt; & Lt; Xsl: apply-select template = "@ * | node ()" /> & Lt; / XSL: Copy & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "@ * [initialize (translate (substring (., 1,4), 'sql', 'SQL'), 'SQL:']]" & gt; & Lt; Xsl: attribute name = "{name ()}" & gt; & Lt; Xsl: Selecting Value = "'From SQL!'" / & Gt; & Lt; / XSL: Specialty & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;  

Result:

  & lt; DM & gt; & Lt; DV ID = "From SQL!" & Gt; & Lt; Sample Help = "From SQL!" & Gt; & Lt; / Sample & gt; & Lt; / DV & gt; & Lt; DV ID = "From SQL!" & Gt; & Lt; Sample Help = "From SQL!" & Gt; & Lt; / Sample & gt; & Lt; / DV & gt; & Lt; / DM & gt;  

Note : There is no need to break "the identity conversion". xsl: attribute .

Add the attributes for the result tree

Comments