Tuesday 15 February 2011

textnode - XSLT remove all text nodes -


I am trying to extract the text nodes without success from the XML document, this XSLT I am using:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Xsl: stylesheet xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" & gt; & Lt; Xsl: output method = "xml" /> & Lt; Xsl: template match = "/ *" & gt; & Lt; XSL: Copy & gt; & Lt; Xsl: apply-select template = "node ()" /> & Lt; / XSL: Copy & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "/ * / *" & gt; & Lt; Xsl: element name = "x" & gt; & Lt; Xsl: attribute name = "attr" & gt; & Lt; Xsl: Select the value = "name ()" /> & Lt; / XSL: Specialty & gt; & Lt; Xsl: apply-select template = "node ()" /> & Lt; / XSL: element & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "/ * / * / a" & gt; & Lt; XSL: Copy & gt; & Lt; Xsl: apply-select template = "node ()" /> & Lt; / XSL: Copy & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "/ * / * / a / *" & gt; & Lt; Xsl: copy-of select = "node ()" /> & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "/ * / * / *" & gt; & Lt; Xsl: copy-of select = "node ()" /> & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "/ * / * / * [no (self: A)]" /> & Lt; Xsl: template match = "text ()" /> & Lt; / XSL: stylesheet & gt;   

line & lt; Xsl: template match = "text ()" & gt; Maybe it is not working because the other lines are more specific (I think), how can I do all the text nodes to delete?

To suppress text nodes, your template is pressing all text nodes that match the matching template Is demanded but it is not for suppressing all text nodes, because not all text nodes are processed using applicable-templates. When you find some nodes (which match the match-pattern / * / * / a / * and / * / * / * , then you have all their children They are copying the nodes without applying templates; If those children have text nodes, or other text-node descendants from those children, those text nodes are avoiding your sketch. Get rid of copy-off calls. , Copy templates together.

No comments:

Post a Comment