xsl-list
[Top] [All Lists]

Re: [xsl] Need XML grep-like tool for Linux that uses XPath expressions

2011-10-12 03:14:16
In addition to all of the excellent suggestions so far, there is
xmlstarlet, which I use for exactly this sort of thing every day. I
typically wrap the command in a shell for loop. E.g., the following
(all on one line, of course) asks for a list of all TEI files that
have within their <text>s one or more naked <reg> elements not
wrapped in <choice>, and for each file a count of such cases:

for f in *.tei ; do
   echo -n "---------$f:" ;
   xmlstarlet sel -N t=http://www.tei-c.org/ns/1.0
   -t -m "/t:TEI/t:text"
   -v "count( .//t:reg[not( parent::t:choice )] )" $f ;
   done | egrep -v ':0$'

The `xmlstarlet sel` subcommand basically let's you execute a small
XSLT 1.0 program from the commandline. The "-t" switch says "here
starts my template", the "-m" switch is for the match= attribute, and
the -v switch is for the select= of an <xsl:value>. There are other
capabilities, too. xmlstarlet also can execute an XSLT stylesheet
file on STDIN from the commandline, although I personally don't use
that much.


Also see the xpath++ utility at
https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14488694#14488694

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--