How to select only specific rows from xml using xsl

A

anywherenotes

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
 
M

Martin Honnen

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.
 

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

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top