XSLT importing a partial XML segment into XML with processing-instructions -


I have an XML document, in which I need to convert specific nodes into partial xml segments, with both nodes Along with processing instructions I want to preserve the PI but I am running into issues in the replacement.

Segment Example: general.xml

  & lt; Root & gt; & Lt ;! - General Settings - & gt; & Lt ;? Mapping environment setting = "envname"? & Gt; & Lt; Setting name = "membership name" value = "*" /> & Lt; / Root & gt;   

Source xml:

  & lt; Environment & gt; & Lt; General /> & Lt; / Environment & gt;   

Transform -

  & lt; Xsl: template match = "* | processing-instructions () | comment ()" & gt; & Lt; XSL: Copy & gt; & Lt; Xsl: copy-of select = "@ *" / & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / XSL: Copy & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "* / normal" & gt; & Lt; Xsl: copy-of select = "document ('general.xml') / root" /> & Lt; / XSL: Templates & gt;   

Output is:

   & Lt; / Root & gt; & Lt; / Environment & gt;   

But I want to:

  & lt; Environment & gt; & Lt ;! - General Settings - & gt; & Lt ;? Mapping environment setting = "envname"? & Gt; & Lt; Setting name = "membership name" value = "*" /> & Lt; / Environment & gt;   

Change the document section to root / * Processing instructions (and comments)

  & lt; Xsl: copy-of select = "document ('general.xml') / root / *" /> ... & lt; Environment & gt; & Lt; Setting name = "membership name" value = "*" /> & Lt; / Environment & gt;   

Changing the document section in the root / process-direction skips the nodes

  & lt; Xsl: copy-of select = "document ('general.xml') / root / processing-instruction ()" /> ... & lt; Environment & gt; & Lt ;? Mapping environment setting = "envname"? & Gt; & Lt; / Environment & gt;   

is trying to do. Matches only the first parameter -

  & lt; Xsl: copy-of select = "document ('general.xml') / root / processing-instruction () | * comment ()" /> ... & lt; Environment & gt; & Lt ;? Mapping environment setting = "envname"? & Gt; & Lt; / Environment & gt;   

So how do I get my cake and eat it? I feel very close, but whatever I have to do, there is a problem finding some examples.

This should do the following:

  & lt; Xsl: template match = "* | processing-instructions () | comment ()" & gt; & Lt; XSL: Copy & gt; & Lt; Xsl: copy-of select = "@ *" / & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / XSL: Copy & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "* / normal" & gt; & Lt; Xsl: Apply-Select Template = "Document ('normal .xml') / root" /> & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "root" & gt; & Lt; Xsl: apply-select template = "node () | @ *" /> & Lt; / XSL: Templates & gt;   

Alternatively, you can copy a number of nodes using the union operator:

  & lt; Xsl: template match = "* / normal" & gt; & Lt; Xsl: variable name = "r" select = "document ('general.xml') / root" / & gt; & Lt; Xsl: Apply-Select Template = "$ r / * $$ r / Resource-Direction () | $ r / Comment ()" /> & Lt; / XSL: Templates & gt;    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -