using xsl file to parse out a chunk of XML

Discussion in 'XML' started by paul_0403@yahoo.com, Jan 7, 2009.

  1. Guest

    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
    , Jan 7, 2009
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Jan 7, 2009
    #2
    1. Advertising

  3. Guest

    On Jan 7, 11:59 am, Martin Honnen <> wrote:
    > 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
    , Jan 7, 2009
    #3
  4. 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:

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


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 7, 2009
    #4
  5. Guest

    On Jan 7, 12:26 pm, Martin Honnen <> wrote:
    > 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:
    >
    >    <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>
    >
    > --
    >
    >         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
    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?
    , Jan 7, 2009
    #5
  6. 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/
    Martin Honnen, Jan 8, 2009
    #6
  7. Guest

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


    Typo - "content" should be "context"
    , Jan 13, 2009
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    3,582
    A. Bolmarcich
    May 27, 2005
  2. Jane Austine
    Replies:
    14
    Views:
    768
    Dennis Lee Bieber
    Oct 9, 2004
  3. gganesh
    Replies:
    2
    Views:
    247
    Minesh Patel
    May 5, 2009
  4. Sanjeeb
    Replies:
    3
    Views:
    406
    Ryan Kelly
    Aug 3, 2010
  5. Jason Kinkade

    hack out chunk from large text file?

    Jason Kinkade, Oct 4, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    117
    Tad McClellan
    Oct 4, 2004
Loading...

Share This Page