using xsl file to parse out a chunk of XML

P

paul_0403

I have the following XML file:

<query id="8124-1228816866" chunk="0" desc="">
<context>id=1005;pid=5208;tid=5400</context>
<a>111</a>
<b>222</b>
<c>333</c>
</query>
<query id="8124-1228816867" chunk="0" desc="">
<context>id=1006;pid=5278;tid=5400</context>
<a>444</a>
<b>555</ba>
<c>666</c>
</query>
.....
.....
.....


Can somebody provide me with an XSL file where I can pass in
values for id, pid and tid and than return a chunk of the XML
(it's okay to put into a temp file).

For example:

If id=1005 pid=5208 tid=5400 I want to the following chunk of XML


<query id="8124-1228816866" chunk="0" desc="">
<context>id=1005;pid=5208;tid=5400</context>
<a>111</a>
<b>222</ba>
<c>333</c>
</query>

Thanks in advance to all that answer this post
 
M

Martin Honnen

I have the following XML file:

<query id="8124-1228816866" chunk="0" desc="">
<context>id=1005;pid=5208;tid=5400</context>
<a>111</a>
<b>222</b>
<c>333</c>
</query>
<query id="8124-1228816867" chunk="0" desc="">
<context>id=1006;pid=5278;tid=5400</context>
<a>444</a>
<b>555</ba>
<c>666</c>
</query>

That is not a well-formed XML document as it lacks a single root element.

Can somebody provide me with an XSL file where I can pass in
values for id, pid and tid and than return a chunk of the XML
(it's okay to put into a temp file).

Do you want to use XSLT 2.0 or 1.0?
 
P

paul_0403

That is not a well-formed XML document as it lacks a single root element.


Do you want to use XSLT 2.0 or 1.0?

The XML document does have a root element I just simplfieid it for the
posting.

As for the verison of XSLT would there be a big difference in the
syntax of the XSL file?

this is the version of xsltproc I am using so what ever will work this
this.

Using libxml 20620, libxslt 10115CVS1047 and libexslt 812CVS1047
xsltproc was compiled against libxml 20623, libxslt 10115 and libexslt
812
libxslt 10115 was compiled against libxml 20623
libexslt 812 was compiled against libxml 20623

Thanks for your help
 
M

Martin Honnen

this is the version of xsltproc I am using so what ever will work this
this.


libxslt is XSLT 1.0. But if all of those params are provided then XSLT
2.0 is not needed I think:

<xsl:param name="id"/>

<xsl:param name="pid"/>

<xsl:param name="tid"/>

<xsl:template match="/">
<xsl:copy-of
select="root/query[content = concat('id=', $id, ';pid=', $pid,
';tid=', $tid)]"/>
</xsl:template>
 
P

paul_0403

this is the version of xsltproc I am using so what ever will work this
this.

libxslt is XSLT 1.0. But if all of those params are provided then XSLT
2.0 is not needed I think:

   <xsl:param name="id"/>

   <xsl:param name="pid"/>

   <xsl:param name="tid"/>

   <xsl:template match="/">
    <xsl:copy-of
      select="root/query[content = concat('id=', $id, ';pid=', $pid,
';tid=', $tid)]"/>
   </xsl:template>


Sorry to bother you but this is what I have and it does not seem to be
working.

a.xsl

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:eek:utput method="text"/>
<xsl:strip-space elements="*"/>

<xsl:param name="id" select = "'UNDEFINED'"/>
<xsl:param name="pid" select = "'UNDEFINED'"/>
<xsl:param name="tid" select = "'UNDEFINED'"/>

<xsl:template match="/">
<xsl:copy-of select="root/query[content = concat('id=',
$id, ';p
d=', $pid, ';tid=', $tid)]"/>
</xsl:template>

</xsl:stylesheet>

the single root element in my XML is <queries>

<queries>
<query id="8124-1228816866" chunk="0" desc="">
<context>id=1005;pid=5208;tid=5400</context>
<a>111</a>
<b>222</b>
<c>333</c>
</query>
<query id="8124-1228816867" chunk="0" desc="">
<context>id=1006;pid=5278;tid=5400</context>
<a>444</a>
<b>555</ba>
<c>666</c>
</query>
</queries>

I am calling it like this:

xsltproc --param id '1005' --param pid '5208' --param tid '5400' ./
a.xsl ./a.xml

Am I missing something?
 
M

Martin Honnen

<xsl:copy-of select="root/query[content = concat('id=',
$id, ';p
d=', $pid, ';tid=', $tid)]"/>
the single root element in my XML is <queries>

Well in that case you need to change the XPath obviously
queries/query[content = concat(...)]"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top