Xsltproc showing error in parsing xml...help required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Xsltproc showing error in parsing xml...help required
# 1  
Old 03-12-2014
Xsltproc showing error in parsing xml...help required

I need to parse text between xml tags using xsltproc. It seems the easiest way.

Here the Input file looks like

Code:
<?xml version="1.0" ?> 
- <tag:ROOT xmlns:as="http://some.org/some.xsd" xmlns:tag="http://www.tag.org/schemas" xmlns:xs="http://some.org/"> 
- <tag:L1> 
- <tag:L2> 
- <tag:L3> 
- <tag:L4> 
- <tag:L5> 
- <tag:L6> 
- <tag:L7> 
- <tag:DATA> 
<tag:DataFlag>False</DataFlag> 
<tag:DataName>Alex</tag:DataName> 
<tag:DataContact>Phone1</tag:DataContact> 
</tag:DATA> 
- <tag:DATA> 
<tag:DataFlag>False</DataFlag> 
<tag:DataName>Mike</tag:DataName> 
<tag:DataContact>Phone2</tag:DataContact> 
</tag:DATA> 
- <tag:DATA> 
<tag:DataFlag>True</DataFlag> 
<tag:DataName>Patty</tag:DataName> 
<tag:DataContact>Phone3</tag:DataContact> 
<tag:DataDesc>user active</tag:DataDesc> 
</tag:DATA> 
</tag:L7> 
</tag:L6> 
</tag:L5> 
</tag:L4> 
</tag:L3> 
</tag:L2> 
</tag:L1>
</tag:ROOT>

I need the output in a text file or a standard o/p as:

Code:
False Alex Phone1
False Mike Phone2
True Patty Phone3

The had tried below code block but it is giving error at line number 5.

Code I had written:

Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select=".//tag:ROOT/tag:L1/tag:L2/tag:L3/tag:L4/tag:L5/tag:L6/tag:L7/tag:DATA>
<xsl:value-of select=".//DataFlag"/>
<xsl:value-of select=".//DataName"/>
<xsl:value-of select=".//DataContact"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Can you please help parsing the attribute in a text OR may be a standard output?

---------- Post updated at 12:12 PM ---------- Previous update was at 10:23 AM ----------

Any help? Please?
# 2  
Old 03-12-2014
You could use awk.

---------- Post updated at 12:34 PM ---------- Previous update was at 12:21 PM ----------

Place this in file x.awk...
Code:
/^<tag:DataFlag>/ {
        split($0,a,">")
        split(a[2],b,"<")
        dataflag=b[1]
        }
/^<tag:DataName>/ {
        split($0,a,">")
        split(a[2],b,"<")
        dataname=b[1]
        }
/^<tag:DataContact>/ {
        split($0,a,">")
        split(a[2],b,"<")
        datacontact=b[1]
        print dataflag,dataname,datacontact
        }

Then do

Code:
awk -f x.awk <xml-file>

This User Gave Thanks to blackrageous For This Post:
# 3  
Old 03-12-2014
Ofcourse I could but i am not that fluent in this... If you give me the code then i would seek your help to explain it...

---------- Post updated at 01:43 PM ---------- Previous update was at 01:34 PM ----------

Thanks blackrageous... This works like a charm...
Can you please explain the code for me?Also, if you please let me know the xslt solution also that would be awesome.Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Covert xml to csv using xsltproc in shell script

Hi, I am not familiar with shell scripting. Please help to convert xml files to csv files using xsltproc command in bash script. Find the xml sample <?xml version="1.0"?> -<Source xmlns="link"> <CompanyCd>DSP</CompanyCd> <SrcSysCd>DSPS</SrcSysCd> <CountryCd>45</CountryCd> ... (2 Replies)
Discussion started by: mathina
2 Replies

2. Shell Programming and Scripting

XML: parsing of the Google contacts XML file

I am trying to parse the XML Google contact file using tools like xmllint and I even dived into the XSL Style Sheets using xsltproc but I get nowhere. I can not supply any sample file as it contains private data but you can download your own contacts using this script: #!/bin/sh # imports... (9 Replies)
Discussion started by: ripat
9 Replies

3. Shell Programming and Scripting

Help required in Splitting a xml file into multiple and appending it in another .xml file

HI All, I have to split a xml file into multiple xml files and append it in another .xml file. for example below is a sample xml and using shell script i have to split it into three xml files and append all the three xmls in a .xml file. Can some one help plz. eg: <?xml version="1.0"?>... (4 Replies)
Discussion started by: ganesan kulasek
4 Replies

4. Shell Programming and Scripting

Extract only required elements from XML.

Hi , I have an XML like this. <Request> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <version>v44</version><messageId>7247308192</messageId><timeToLive>72000000000</timeToLive> </Request>. I want to extract on version and messageId. As in my output... (13 Replies)
Discussion started by: chetan.c
13 Replies

5. UNIX for Advanced & Expert Users

Perl parsing help required.

Hello, I got a file like this. 5201 5202 5203 5204 1234 2345 3456 4567 6210 6220 6230 6240 The required output should be 5201 1234 6210 (9 Replies)
Discussion started by: suverman
9 Replies

6. Shell Programming and Scripting

Help required in parsing a csv file

Hi Members, I am stuck with the following problem. Request your kind help I have an csv file which contains, 1 header record, data records and 1 footer record. Sample is as below Contents of cm_update_file_101010.csv -------------------------------------------------- ... (6 Replies)
Discussion started by: ramakanth_burra
6 Replies

7. Shell Programming and Scripting

XML parsing

I have a xml file attached. I need to parse parameterId and its value My output should be like 151515 38 151522 32769 and so on.. Please help me. Its urgent (6 Replies)
Discussion started by: LavanyaP
6 Replies

8. Shell Programming and Scripting

Facing issue while using xsltproc tp parse XML in bash

I have written a bash script which opens a folder, reads all the *.xml files in it, and pulls the required data that i need from XML tags. I am using xsltproc (my xsl name) (my xml folder location/*.xml) and running this in a for each loop The problem is that some XML files are having special... (3 Replies)
Discussion started by: shivashankar.g
3 Replies

9. Shell Programming and Scripting

XML Parsing

Hi, Need a script to parse the following xml file content <tag1 Name="val1"> <abc Name="key"/> <abc Name="pass">*********</abc> </tag1> <tag2 Name="Core"> <Host Name="a.b.c"> <tag1 Name="abc"> <abc Name="ac">None</abc> ... (4 Replies)
Discussion started by: Mavericc
4 Replies

10. UNIX for Advanced & Expert Users

xml parsing error in perl

******************PERL VERSION************************ This is perl, v5.8.1 built for i386-linux-thread-multi ERROR!!!!---Undefined subroutine &main::start called at /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi/XML/Parser/Expat.pm line 469. *********************PERL... (1 Reply)
Discussion started by: bishweshwar
1 Replies
Login or Register to Ask a Question