This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Counting nodes - now specifying body in stylesheet


Thanks for the suggestions.

Regarding the namespace I am using, one of the reasons I have not moved to
the newer namespace is that I cannot seem to make an output stylesheet look
very nice using the http://www.w3.org/1999/XSL/Transform namespace.

Perhaps, someone could give me suggestions with this problem:

The biggest issue I have is when I try to define the body of the stylesheet.
In the example below, I have a couple simple xsl commands, and I've defined
a body with a background color.

Normally, I would get a list of all the
"metadata/idinfo/citation/citeinfo/onlink" elements, followed by the
"metadata/idinfo/citation/citeinfo/origin" element.  However, once I have
entered the "<body>" tag, every xsl command following the for-each command
end up blank - the "metadata/idinfo/citation/citeinfo/origin" will not
appear in the result, and I get no processing errors.  If the "<body>" tag
and it's closing tag "</body>" are removed from the code below, then
everything works fine, but I'm stuck with unformatted results.

I've tried looking at formatting objects in XSL, but haven't been able to
get anything to work yet.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:template match="/">
<HTML>
<body bgcolor="#cccccc">

<xsl:for-each select="metadata/idinfo/citation/citeinfo/onlink">
    <xsl:value-of select="." />
    <xsl:if test="current()[(position() != last())]">
        <br/>
    </xsl:if>
</xsl:for-each>

<xsl:value-of select="metadata/idinfo/citation/citeinfo/origin"/>

</body>
</HTML>
</xsl:template>
</xsl:stylesheet>


----- Original Message -----
From: "Andrew Welch" <awelch@piper-group.com>
To: <xsl-list@lists.mulberrytech.com>
Sent: Tuesday, July 02, 2002 10:24 AM
Subject: RE: [xsl] Counting nodes


>
> wd-xsl doesnt have a count function, so you have to write your own.
> This should do what you want:
>
> function count(obj,tagName) {
>     var a = getElementsByTagName(tagName);
>     return a.length;
>   }
>
> Pass to it the parent element which contains all of the nodes you wish
> to count, and the element name.  For example:
>
> <xsl:template match="lineage">
>   <xsl:eval>count(this,'procstep')</xsl:eval>
> </xsl:template>
>
> Or, the less reusable but ultimately better:
>
> <xsl:template match="lineage">
>   <xsl:eval>getElementsByTagName('procstep').length</xsl:eval>
> </xsl:template>
>
> Of course, to save your head from bursting, its easier to move to XSLT
> and use the count() function or <xsl:number>
>
> cheers
> andrew
>
> -----Original Message-----
> From: Mike Leahy [mailto:mgleahy@fes.uwaterloo.ca]
> Sent: 02 July 2002 14:52
> To: XSL-List@lists.mulberrytech.com
> Subject: [xsl] Counting nodes
>
>
> Hello list,
>
> I am using the namespace "http://www.w3.org/TR/WD-xsl";
>
> I would like to be able to count the occurrance of a particular tag
> (e.g.
> "procstep" can occur multiple times within "metadata/dataqual/lineage"
> in
> the XML files I am using).  The count function is not a recognized
> function
> in the namespace I am using - is there any other way I could get this
> number?
>
> Mike
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]