Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > using xsl file to parse out a chunk of XML

Reply
Thread Tools

using xsl file to parse out a chunk of XML

 
 
paul_0403@yahoo.com
Guest
Posts: n/a
 
      01-07-2009
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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      01-07-2009
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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?

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
paul_0403@yahoo.com
Guest
Posts: n/a
 
      01-07-2009
On Jan 7, 11:59*am, Martin Honnen <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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?
>
> --
>
> * * * * Martin Honnen
> * * * *http://JavaScript.FAQTs.com/


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
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      01-07-2009
(E-Mail Removed) wrote:

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

<xslaram name="id"/>

<xslaram name="pid"/>

<xslaram name="tid"/>

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


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
paul_0403@yahoo.com
Guest
Posts: n/a
 
      01-07-2009
On Jan 7, 12:26*pm, Martin Honnen <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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:
>
> * *<xslaram name="id"/>
>
> * *<xslaram name="pid"/>
>
> * *<xslaram name="tid"/>
>
> * *<xsl:template match="/">
> * * <xsl:copy-of
> * * * select="root/query[content = concat('id=', $id, ';pid=', $pid,
> ';tid=', $tid)]"/>
> * *</xsl:template>
>
> --
>
> * * * * Martin Honnen
> * * * *http://JavaScript.FAQTs.com/



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

a.xsl

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

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

<xslaram name="id" select = "'UNDEFINED'"/>
<xslaram name="pid" select = "'UNDEFINED'"/>
<xslaram 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?

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      01-08-2009
(E-Mail Removed) wrote:

> <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(...)]"

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
fpm@hotmail.com
Guest
Posts: n/a
 
      01-13-2009
> Well in that case you need to change the XPath obviously
> queries/query[content = concat(...)]"


Typo - "content" should be "context"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sending a file chunk by chunk instead as a whole to a web server Sanjeeb Python 3 08-03-2010 05:52 AM
Is there is any way to send messages to chunk of emails ID'sconcurrently using smptlib gganesh Python 2 05-05-2009 05:39 PM
What is an AVI Chunk Viewer? - AVI Chunk Viewer.jpg (0/1) mazdra76@yahooo.com Computer Support 1 03-17-2006 02:52 AM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
hack out chunk from large text file? Jason Kinkade Perl Misc 3 10-04-2004 12:41 PM



Advertisments