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

<?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:

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:

<?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?

You could use awk.

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

Place this in file x.awk...

/^<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

awk -f x.awk <xml-file>
1 Like

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.