Sponsored Content
Full Discussion: parse xml file
Top Forums Shell Programming and Scripting parse xml file Post 302464210 by cabrao on Wednesday 20th of October 2010 05:16:56 AM
Old 10-20-2010
Perfect!
I didn't know xsltproc, thanks for your great help and time fpmurphy! Smilie

---------- Post updated 20th Oct 2010 at 11:16 AM ---------- Previous update was 19th Oct 2010 at 08:03 PM ----------

EDIT:
xsltproc is very powerfull and in order to improve my results I added the following code in your example.xsl :
Code:
   <xsl:template match="/">
       <xsl:apply-templates select="//QUANTITATIVE" />
   </xsl:template>

   <xsl:template match="QUANTITATIVE">
      <xsl:if test='contains(@NAME, $search)'>
         <xsl:value-of select="../@JOBNAME" />
         <xsl:text> </xsl:text>
         <xsl:value-of select="@NAME" />
         <xsl:text> </xsl:text>
         <xsl:value-of select="@QUANT" />
         <xsl:text> </xsl:text>
         <xsl:text>
</xsl:text>
      </xsl:if>
   </xsl:template>

This new code is working fine, the only thing is that when I do a command xsltproc -param search "'KEYWORD'" if KEYWORD exists in (OUTCOND or INCOND) and in QUANTITATIVE template it will print all matching results at the same time.

Is there a way to pass a parameter via xsltproc command line or something in order to print only (OUTCOND or INCOND) or QUANTITATIVE with just one example.xsl file ?

A solution would be to create multiples .xsl files but I would rather prefer having just one. Any idea fpmurphy or someone else ? Smilie

Thanks for the attention!

Last edited by cabrao; 10-20-2010 at 06:16 AM.. Reason: New question
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies

2. Shell Programming and Scripting

Parse XML file

Hi, I need to parse the following XML data enclosed in <a> </a> XML tag using shell script. <X> ..... </X> <a> <b> <c>data1</c> <c>data2</c> </b> <d> <c>data3</c> </d> </a> <XX> ... </XX> (5 Replies)
Discussion started by: viki
5 Replies

3. Shell Programming and Scripting

Parse String in XML file

Hello All, I am new to this and I need to parse an XML file. Here's the XML Input File: <Report version="1.2"> <summary fatals="0" testcases="1" expected_fails="0" unexpected_passes="0" warnings="9" tests="21" errors="0" fails="1" passes="20" /> <testresult... (4 Replies)
Discussion started by: racbern
4 Replies

4. Shell Programming and Scripting

How can I parse xml file?

How can I parse file containing xml ? I am sure that its best to use perl - but my perl is not very good - can someone help? Example below contents of file containing the xml - I basically want to parse the file and have each field contained in a variable.. ie. I want to store the account... (14 Replies)
Discussion started by: frustrated1
14 Replies

5. Shell Programming and Scripting

Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as <TASKLIST <TASK definition="Completion date" id="Taskname1" Some other <CODE name="Code12" <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter> <Parameter... (3 Replies)
Discussion started by: MissI
3 Replies

6. Emergency UNIX and Linux Support

How to parse the following xml file

Hi, I have the following file Example.xml <?xml version="1.0" encoding="iso-8859-1"?> <html><set label="09/07/29" value="1241.90"/> </html> Can any one help me in parsing this xml file I want to retrive the attribute values of the tag set Example I want to... (3 Replies)
Discussion started by: Raji_gadam
3 Replies

7. Programming

Parse XML file

How do I get the field info for tags ID, NAME, DESCRIPTION. Below is my current code put I can't get beyond the first_child of the file. use strict; use warnings; use XML::Simplehttp://images.intellitxt.com/ast/adTypes/icon1.png; use... (1 Reply)
Discussion started by: leemalloy
1 Replies

8. UNIX for Dummies Questions & Answers

Parse xml file

HI Guys, Input .XML <xn:MeContext id="L0307"> <xn:ManagedElement id="1"> <xn:VsDataContainer id="1"> <xn:attributes> <xn:vsDataType>vsDataENodeBFunction</xn:vsDataType> ... (3 Replies)
Discussion started by: pareshkp
3 Replies

9. Shell Programming and Scripting

Parse XML File.

HI Guys I have Below XML File : <xn:SubNetwork id="XYZ"> <xn:SubNetwork id="C01"> <xn:MeContext id="CO1"> <xn:ManagedElement id="1"> <un:RncFunction id="1"> <un:UtranCell id="NY431"> ... (2 Replies)
Discussion started by: pareshkp
2 Replies

10. Shell Programming and Scripting

Parse xml file

I am trying to create a shell script that will parse an xml file (file attached). awk '/Id v=/ { print }' Test.xml | sed 's!<Id v=\"\(.*\)\"/>!\1!' > output.txt An output.txt file is created but it is empty. It should contain the value 222159 in it. Thanks. (7 Replies)
Discussion started by: cmccabe
7 Replies
XSLTPROC(1)							  xsltproc Manual						       XSLTPROC(1)

NAME
xsltproc - command line XSLT processor SYNOPSIS
xsltproc [[-V | --version] [-v | --verbose] [{-o | --output} {FILE | DIRECTORY}] | --timing | --repeat | --debug | --novalid | --noout | --maxdepth VALUE | --html | --encoding ENCODING | --param PARAMNAME PARAMVALUE | --stringparam PARAMNAME PARAMVALUE | --nonet | --path "PATH(S)" | --load-trace | --catalogs | --xinclude | [--profile | --norman] | --dumpextensions | --nowrite | --nomkdir | --writesubtree PATH | --nodtdattr] [STYLESHEET] {XML-FILE | -} DESCRIPTION
xsltproc is a command line tool for applying XSLT stylesheets to XML documents. It is part of libxslt(3), the XSLT C library for GNOME. While it was developed as part of the GNOME project, it can operate independently of the GNOME desktop. xsltproc is invoked from the command line with the name of the stylesheet to be used followed by the name of the file or files to which the stylesheet is to be applied. It will use the standard input if a filename provided is - If a stylesheet is included in an XML document with a Stylesheet Processing Instruction, no stylesheet need to be named at the command line. xsltproc will automatically detect the included stylesheet and use it. By default, output is to stdout. You can specify a file for output using the -o or --output option. OPTIONS
xsltproc accepts the following options (in alphabetical order): --catalogs Use the SGML catalog specified in SGML_CATALOG_FILES to resolve the location of external entities. By default, xsltproc looks for the catalog specified in XML_CATALOG_FILES. If that is not specified, it uses /etc/xml/catalog. --debug Output an XML tree of the transformed document for debugging purposes. --dumpextensions Dumps the list of all registered extensions on stdout. --html The input document is an HTML file. --load-trace Display all the documents loaded during the processing to stderr. --maxdepth VALUE Adjust the maximum depth of the template stack before libxslt(3) concludes it is in an infinite loop. The default is 3000. --nodtdattr Do not apply default attributes from the document's DTD. --nomkdir Refuses to create directories. --nonet Do not use the Internet to fetch DTDs, entities or documents. --noout Do not output the result. --novalid Skip loading the document's DTD. --nowrite Refuses to write to any file or resource. -o or --output FILE | DIRECTORY Direct output to the given FILE. Using the option with a DIRECTORY directs the output files to the specified directory. This can be useful for multiple outputs (also known as "chunking") or manpage processing. Important The given directory must already exist. Note Make sure that FILE and DIRECTORY follow the "URI reference computation" as described in RFC 2396 and laters. This means, that e.g. -o directory will maybe not work, but -o directory/ will. --encoding ENCODING Allow to specify the encoding for the input. --param PARAMNAME PARAMVALUE Pass a parameter of name PARAMNAME and value PARAMVALUE to the stylesheet. You may pass multiple name/value pairs up to a maximum of 32. If the value being passed is a string, you can use --stringparam instead, to avoid additional quote characters that appear in string expressions. Note: the XPath expression must be UTF-8 encoded. --path "PATH(S)" Use the (space- or colon-separated) list of filesystem paths specified by PATHS to load DTDs, entities or documents. Enclose space-separated lists by quotation marks. --profile or --norman Output profiling information detailing the amount of time spent in each part of the stylesheet. This is useful in optimizing stylesheet performance. --repeat Run the transformation 20 times. Used for timing tests. --stringparam PARAMNAME PARAMVALUE Pass a parameter of name PARAMNAME and value PARAMVALUE where PARAMVALUE is a string rather than a node identifier. Note: The string must be UTF-8 encoded. --timing Display the time used for parsing the stylesheet, parsing the document and applying the stylesheet and saving the result. Displayed in milliseconds. -v or --verbose Output each step taken by xsltproc in processing the stylesheet and the document. -V or --version Show the version of libxml(3) and libxslt(3) used. --writesubtree PATH Allow file write only within the PATH subtree. --xinclude Process the input document using the XInclude specification. More details on this can be found in the XInclude specification: http://www.w3.org/TR/xinclude/ ENVIRONMENT
SGML_CATALOG_FILES SGML catalog behavior can be changed by redirecting queries to the user's own set of catalogs. This can be done by setting the SGML_CATALOG_FILES environment variable to a list of catalogs. An empty one should deactivate loading the default /etc/sgml/catalog catalog. XML_CATALOG_FILES XML catalog behavior can be changed by redirecting queries to the user's own set of catalogs. This can be done by setting the XML_CATALOG_FILES environment variable to a list of catalogs. An empty one should deactivate loading the default /etc/xml/catalog catalog. DIAGNOSTICS
xsltproc return codes provide information that can be used when calling it from scripts. 0 No error (normal operation) 1 No argument 2 Too many parameters 3 Unknown option 4 Failed to parse the stylesheet 5 Error in the stylesheet 6 Error in one of the documents 7 Unsupported xsl:output method 8 String parameter contains both quote and double-quotes 9 Internal processing error 10 Processing was stopped by a terminating message 11 Could not write the result to the output file SEE ALSO
libxml(3), libxslt(3) More information can be found at o libxml(3) web page http://www.xmlsoft.org/ o W3C XSLT page http://www.w3.org/TR/xslt AUTHOR
John Fleck <jfleck@inkstain.net> Author. COPYRIGHT
Copyright (C) 2001, 2002 libxslt $Date: 2008-04-21 16:28:56 +0200 (Mon, 21 Apr 2008) $ XSLTPROC(1)
All times are GMT -4. The time now is 05:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy