Copy XML for each specific child node keeping one complete copy for each child node using XSLT? -


itempop = "text">

I have the same XML I want to "record", if you do, XML based on the authors. So for every author kid node, I want all copies of all XML for all copies and just a one author hair node. I got it, but hanging me properly by generating authors. I have appreciated any help!

Sample:

  & lt; Root & gt; & Lt; Book & gt; & Lt; Name & gt; ... some data & lt; / Name & gt; & Lt; Information & gt; ... some data & lt; / Info & gt; & Lt; Writers & gt; & Lt; Author & gt; Author 1 & lt; / Author & gt; & Lt; Author & gt; Author 2 & lt; / Author & gt; & Lt; / Authors & gt; Other nodes & lt; / Book & gt; & Lt; / Root & gt; ====================== Output: & lt; Root & gt; & Lt; Book & gt; & Lt; Name & gt; ... some data & lt; / Name & gt; & Lt; Information & gt; ... some data & lt; / Info & gt; & Lt; Writers & gt; & Lt; Author & gt; Author 1 & lt; / Author & gt; & Lt; / Authors & gt; Other nodes & lt; / Book & gt; & Lt; / Root & gt; & Lt; Root & gt; & Lt; Book & gt; & Lt; Name & gt; ... some data & lt; / Name & gt; & Lt; Information & gt; ... some data & lt; / Info & gt; & Lt; Writers & gt; & Lt; Author & gt; Author 2 & lt; / Author & gt; & Lt; / Authors & gt; Other nodes & lt; / Book & gt; & Lt; / Root & gt;  

This is not exactly trivial - try:

< Strong> XSLT 1.0

  & lt; Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" & gt; & Lt; Xsl: output method = "xml" version = "1.0" encoding = "UTF-8" indent = "yes" /> & Lt; Xsl: strip-space element = "*" /> & Lt; Xsl: template match = "/ root" & gt; & Lt; XSL: Copy & gt; & Lt; Xsl: each selection = "book / author / author" & gt; & Lt; Xsl: Apply-Select Template = "Ancestors :: Book" & gt; & Lt; Xsl: with -name = "author" = "." / & Gt; & Lt; / XSL: implemented-templates & gt; & Lt; / XSL: for-each & gt; & Lt; / XSL: Copy & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "*" & gt; & Lt; Xsl: Ultimate Name = "Author" /> & Lt; XSL: Copy & gt; & Lt; Xsl: Apply-Select Template = "node ()" & gt; & Lt; With xsl: select param name = "author" = "$ author" /> & Lt; / XSL: implemented-templates & gt; & Lt; / XSL: Copy & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: Template Match = "Author" & gt; & Lt; Xsl: Ultimate Name = "Author" /> & Lt; Xsl: if test = ". $ = Author" & gt; & Lt; Xsl: copy-of select = "." / & Gt; & Lt; / XSL: If & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;  

Note: If you can use the XSLT 2.0 processor, read on parameter tunneling; Which will make it a bit less complex


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -