How to select only specific rows from xml using xsl

Discussion in 'XML' started by anywherenotes@gmail.com, Feb 6, 2009.

  1. Guest

    Hi,

    I currently have the following xsl file:
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput method="text" omit-xml-declaration="yes" indent="no"/>
    <xsl:param name="user" select = "''"/>
    <xsl:template match="query">
    <xsl:choose>
    <xsl:when test="exception[name and contains(user,
    $user)]">status="exception" user="<xsl:value-of select="user"/>"
    exception="<xsl:value-of select="exception/name"/>"</xsl:when>
    </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>

    And this is the XML file:
    <queries>
    <query id="123" chunk="0" desc="">
    <user>something</user>
    <exception>
    <name>bob</name>
    <description>some error</description>
    <time>2007-07-25 15:01:54</time>
    </exception>
    </query>
    <query id="456" chunk="0" desc="">
    <user>something else</user>
    </query>
    </queries>

    And my output is:
    $ c:/axssrvr_380/bin/xsltproc sample.xsl sample.xml

    status="exception" user="something" exception="bob"

    $

    I'd like to get this:
    $ c:/axssrvr_380/bin/xsltproc sample.xsl sample.xml
    status="exception" user="something" exception="bob"
    $

    I'm not clear where the blank lines are coming from, if I pipe output
    into 'wc', I get 3 lines, so it's not a long line that's wrapping
    around, but rather 3 lines, where I would only expect to get 1.

    Thank you.
    Alex
    , Feb 6, 2009
    #1
    1. Advertising

  2. wrote:

    > And my output is:
    > $ c:/axssrvr_380/bin/xsltproc sample.xsl sample.xml
    >
    > status="exception" user="something" exception="bob"
    >
    > $
    >
    > I'd like to get this:
    > $ c:/axssrvr_380/bin/xsltproc sample.xsl sample.xml
    > status="exception" user="something" exception="bob"
    > $
    >
    > I'm not clear where the blank lines are coming from,


    Add
    <xsl:template match="/">
    <xsl:apply-templates select="queries/query"/>
    </xsl:template>
    otherwise whitespace text nodes inside of the queries element are copied
    through to the output by default templates.

    As an alternative do
    <xsl:strip-space elements="*"/>
    as a top-level element in the stylesheet, that would get rid of the
    whitespace too.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 6, 2009
    #2
    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. 5tein
    Replies:
    1
    Views:
    472
    Patrick TJ McPhee
    Apr 30, 2004
  2. Replies:
    2
    Views:
    1,588
    Dimitre Novatchev
    May 18, 2005
  3. Replies:
    1
    Views:
    3,600
    A. Bolmarcich
    May 27, 2005
  4. William  Krick
    Replies:
    4
    Views:
    14,335
    anntenna
    Mar 18, 2011
  5. enggr
    Replies:
    0
    Views:
    1,633
    enggr
    Jun 30, 2010
Loading...

Share This Page