[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl][xslt v1.0] How to parse the string as node-set?


Subject: Re: [xsl][xslt v1.0] How to parse the string as node-set?
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Sun, 30 Sep 2012 09:56:28 -0400

[Hmmm. I sent this 2012-09-29 10:14 (before I had received Ken
Holman's "2 steps or vendor extension" reply), but it doesn't seem to
have made it to the list. Since the technique demonstrated for doing
2 XSLT steps from a shell commandline is potentially useful to OP and
others, I'm trying again.]

I'd do this in two passes. Presuming you have "xmlstarlet" installed
and in your shell path as `xmlstarlet`[1], the following (all on one
line, of course) should do the trick.

$ xmlstarlet select --text
    -N T=http://xmlexchangeservice.com/
    --template
    --match "//T:InputXML"
    --value-of "."
    input.xml
    |
    xmlstarlet select
      -N tns=urn:schemas:x12:org:V00200806:CoverageRequest
      --xml-decl
      --template
      --match "//tns:Organization"
      --copy-of "."

(I've used long options to make it clearer to readers who aren't
familiar with xmlstarlet's switches.)

If you don't have xmlstarlet, you can obviously do the same thing by
actually writing the two stylesheets: one that extracts <InputXML>
into a file as text, and another that reads in that file as XML.

Notes
-----
[1] Some package managers install xmlstarlet as the `xml` command.


Current Thread
Keywords