Subject: RE: Is this the best way to emit one line per occurrence of an xpath?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 9 Nov 2007 17:31:19 -0000
|
> That's what I would have thought, but I noticed that it
> appeared to make not a bit of difference. Under what
> circumstances would that actually make any difference in the output?
It would make a difference if your text contained a character such as "<" or
"&". The XML output method would escape it, the text output method would
not.
Michael Kay
http://www.saxonica.com/
>
> > -----Original Message-----
> > From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
> > Sent: Thursday, November 08, 2007 3:20 PM
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: RE: Is this the best way to emit one line per
> > occurrence of an xpath?
> >
> > My only suggestion would be that method="text" is more appropriate
> > here than method="xml".
> >
> > Michael Kay
> > http://www.saxonica.com/
> >
> > > -----Original Message-----
> > > From: Karr, David [mailto:david.karr@xxxxxxxx]
> > > Sent: 08 November 2007 22:13
> > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > Subject: Is this the best way to emit one line per
> > occurrence of
> > > an xpath?
> > >
> > > I had to write a simple stylesheet that prints out in
> text form one
> > > line of text for every occurrence of a particular xpath
> in an input
> > > xml file.
> > > I think I got it working, but I just wanted to ask for a
> > critique of
> > > this, to see if there are different ways of doing this.
> > >
> > > The following is what I have so far:
> > > --------------------------
> > > <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet
> > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > > version="1.0">
> > >
> > > <xsl:output method="xml" omit-xml-declaration="yes"/>
> > >
> > > <xsl:template match="/">
> > > <xsl:apply-templates
> > > select="/beans/bean[@singleton!='false']/@class"/>
> > > </xsl:template>
> > >
> > > <xsl:template match="@class">
> > > <xsl:value-of select="normalize-space(.)"/><xsl:text>
> > > </xsl:text>
> > > </xsl:template>
> > >
> > > </xsl:stylesheet>
> > > --------------------------
> > >
> > > This produces output like this:
> > >
> > > --------------------------
> > > org.apache.commons.chain.impl.ChainBase
> > > com.wamu.stuff.Gork
> > > com.wamu.foo.Bar
> > > com.wamu.uia.framework.AdapterController
> > > com.wamu.uia.adapter.HttpClientAdapter
> > > --------------------------
> > >
> > > Again, this is exactly what I want, I was just wondering about
> > > alternatives for doing the same thing.
|