Re: [xsl] Counting nodes - now specifying body in stylesheet

Subject: Re: [xsl] Counting nodes - now specifying body in stylesheet
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 02 Jul 2002 11:49:44 -0400
Mike,

Definitely switch to XSLT. The sooner you switch, the more grief you'll save yourself.

At 11:12 AM 7/2/2002, you wrote:
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.

Honestly, this is baffling. Please test very carefully (using the same XPath expressions in your for-each select) to confirm that it's the presence or absence of the <body> node that makes the difference. There's no way in XSLT it should; it does not change the context for the evaluation of any expressions.


Which processor are you using?

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

If you're targetting web display, write XSLT that creates HTML (for now). At present FOs are still being used mainly to generate print output (e.g. in PDF).


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

If you're not getting your values reported, it's probably because this XPath returns no nodes. Does your source look more or less like


<?xml version="1.0"?>
<metadata>
  <idinfo>
    <citation>
      <citeinfo>
        <onlink>Here's the value you want</onlink>
      </citeinfo>
    </citation>
  </idinfo>
</metadata>

<metadata> being your document ("root") element? If not, your XPath won't work. (If you post a snippet of your source, it's easy enough to see what XPath you need.)

    <xsl:value-of select="." />
    <xsl:if test="current()[(position() != last())]">

This should be (position() != last())
The test as given is never true (since the position of a node is always last when it's the only node selected).


        <br/>
    </xsl:if>
</xsl:for-each>

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

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

From the design of this stylesheet, it also looks like you might want to do a bit of homework on templates. You don't really need them for this simple application, but you will.


Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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



Current Thread