xml - XSLT to Transform the child Node name according to their occurrence -
I need to write an XSLT, which will change the node name, I will see it during my presence < / P>
XML Current: XML Requirement Check the name and item price prize. In this way I have 100 commands in an XML of commands It is possible to change the identity changes and just change the bit bits that you want to change to make the most XML unchanged copy using a stylesheet: If you want to leave the first event of each element alone and start the number from the other, then you can do the template match in XSLT 2.0 By tweaking the pattern: But in XSLT 1.0 you can not use the At the more general level, this is not a very bad option for XML format - more to use and express similar personality to use similar names in the same elements. Normal is the reliance between different elements through nesting rather than the situation, such as & lt; Order & gt; & Lt; Order & gt; & Lt; OrderNo & gt; ABC & lt; / OrderNo & gt; & Lt; ItemDetails & gt; & Lt; Name & gt; Shirt & lt; / Name & gt; & Lt; Name & gt; Socks & lt; / Name & gt; & Lt; ItemPrice & gt; 30 & lt; / ItemPrice & gt; & Lt; ItemPrice & gt; 40 & lt; / ItemPrice & gt; & Lt; / ItemDetails & gt; & Lt; / Order & gt; & Lt; / Order & gt;
& lt; Order & gt; & Lt; Order & gt; & Lt; OrderNo & gt; ABC & lt; / OrderNo & gt; & Lt; ItemDetails & gt; & Lt; NAME1 & gt; Shirt & lt; / Name & gt; & Lt; NAME2 & gt; Socks & lt; / Name & gt; & Lt; ItemPrice1 & gt; 30 & lt; / ItemPrice & gt; & Lt; ItemPrice2 & gt; 40 & lt; / ItemPrice & gt; & Lt; / ItemDetails & gt; & Lt; / Order & gt; & Lt; / Order & gt;
< Code> & lt; Xsl: stylesheet xmlns: xsl = "http://www.w3.org/1990/XSL/transform" version = "1.0" & 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 = "Item Details / *" & gt; & Lt; Xsl: element name = "{name ()} {count (predecessor-cybling :: * [name () = name (current ())]) + 1}" & gt; & Lt; xsl: apply-select template = "@ * | node ()" /> & Lt; / XSL: element & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;
& lt; Xsl: template match = "item info / * [predecessor-cybling :: * [name () = name (current ())]]" & gt; & Lt; Xsl: element name = "{name ()} {count (predecessor-cybling :: * [name () = name (current ())])" & gt; & Lt; xsl: apply-select template = "@ * | node ()" /> & Lt; / XSL: element & gt; & Lt; / XSL: Templates & gt;
current in
match pattern, so you can use it for the template's body. Check inside, like
& lt; xsl: template match = "@ * | node ()" name = "ident" & gt; & Lt; xsl: Copy & gt; & Lt; xsl: apply-select template = "@ * | node ()" /> & Lt; / xsl: Copy & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: Template Match = "Item Details / *" & gt; & Lt; XSL: Select & gt; & Lt; Xsl: when test = "predecessor-siblings :: * [name () = name (current ())]" & gt; & Lt; Xsl: element name = "{name ()} {count (predecessor-cybling :: * [name () = name (current ())])" & gt; & Lt; xsl: apply-select template = "@ * | node ()" /> & Lt; / XSL: element & gt; & Lt; / XSL: When & gt; & Lt; XSL: otherwise & gt; & Lt ;! - This is the first element of this name, so return it back to practice behavior - & gt; & Lt; Xsl: call-template name = "identity" /> & Lt; / XSL: otherwise & gt; & Lt; / XSL: Select & gt; & Lt; / XSL: Templates & gt;
Comments
Post a Comment