xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: "Jacobs, Robert A." <ra.jacobs AT ngc.com>
- To: "Michael Kay" <mike AT saxonica.com>, "XOM (E-mail)" <xom-interest AT lists.ibiblio.org>
- Cc:
- Subject: RE: [XOM-interest] XSLTransform
- Date: Thu, 31 Mar 2005 11:01:36 -0600
Thanks for the suggestions. I'll track them down
and take a look.
Like I said, I'm new to this so suggestions on
style changes are very helpful.
-----Original Message-----
From: Michael Kay [mailto:mike AT saxonica.com]
Sent: Thursday, March 31, 2005 10:59 AM
To: Jacobs, Robert A.; 'XOM (E-mail)'
Subject: RE: [XOM-interest] XSLTransform
The task element is in a namespace, so declare
xmlns:jtt="http://mil.jcsj2t.jtt30"
at the start of your stylesheet, and replace all references to task (in
XPath expressions and XSLT patterns) with jtt:task. The same applies to any
other references to elements that are in a namespace.
There are quite a few other stylistic things you could improve here. The
place for this is really the xsl-list at mulberrytech.com.
Most notably,
(a) this kind of logic:
<xsl:for-each select="node()">
<xsl:choose>
<xsl:when test="local-name() = 'option'">
is crying out to be replaced by xsl:apply-templates, with a template rule
for each of the possible elements you might encounter.
(b) avoid //task unless you aren't able to supply a more specific path (e.g.
/*/task)
(c) this kind of thing:
<a><xsl:attribute name="href">
>
> <xsl:text>javascript:get_explanation('</xsl:text>
> <xsl:value-of select='@id' />
> <xsl:text>');</xsl:text>
> </xsl:attribute>
> <xsl:value-of select="title"/>
> </a>
gives XSLT its reputation for verbosity. It can be written:
<a href="javascript:get_explanation('{@id}');">
<xsl:value-of select="title"/>
</a>
Michael Kay
> -----Original Message-----
> From: Jacobs, Robert A. [mailto:ra.jacobs AT ngc.com]
> Sent: 31 March 2005 17:01
> To: Michael Kay; XOM (E-mail)
> Subject: RE: [XOM-interest] XSLTransform
>
>
> >> I thought I followed the guidance in "XML in a Nutshell"
> >> fairly well, but
> >> perhaps I didn't. Here are some fragments from my
> XMLSchema-instance
> >> document and my XMLSchema document. Anything stand out as
> erroneous?
>
> > No, but you haven't shown us any stylesheet code.
>
> Here you go:
>
> --------------------- code -----------------------
>
> <?xml version="1.0" ?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <!-- CONFIGURATION -->
> <xsl:output method="html" />
>
> <!-- GLOBAL VARIABLES -->
> <xsl:key name="task.id" match="task" use="@id" />
> <xsl:param name="selected.task.id"> </xsl:param>
> <xsl:param name="selected.mode"> </xsl:param>
>
> <!-- TEMPLATES -->
>
> <!-- The "driver". Based upon the submitted parameters,
> the driver
> directs the Transformer to the appropriate
> processing template -->
> <xsl:template match="/">
> <xsl:choose>
> <xsl:when test="$selected.mode = 'task_list'">
> <xsl:apply-templates select="//task[@id =
> $selected.task.id]" mode="task_list" />
> </xsl:when>
> <xsl:when test="$selected.mode = 'task_desc'">
> <xsl:apply-templates select="//task[@id =
> $selected.task.id]" mode="task_desc" />
> </xsl:when>
> </xsl:choose>
> </xsl:template>
>
> <!-- This template is used to build a list of task titles
> based upon the ID
> of a discrete- or meta-task selected either from the
> search results or from
> an existing list of tasks.
> -->
> <xsl:template match="task" mode="task_list">
> <xsl:choose>
>
> <xsl:when test="@task_type='meta'">
> <xsl:value-of select="title"/><br/>
> <ol>
> <xsl:for-each select="node()">
> <!-- DEBUG: Looking at: <xsl:value-of
> select="local-name()" /> -->
> <xsl:choose>
>
> <xsl:when test="local-name() = 'option'">
> <li>Select one of the following:<br/>
> <ul>
> <xsl:for-each select="current()/step">
> <xsl:variable
> name="step_idref" select="current()" />
> <li>
> <a><xsl:attribute name="href">
>
> <xsl:text>javascript:get_explanation('</xsl:text>
> <xsl:value-of
> select="$step_idref" />
> <xsl:text>');</xsl:text>
> </xsl:attribute>
> <xsl:value-of
> select="//task[@id=$step_idref]/title"/>
> </a>
> </li>
> </xsl:for-each>
> </ul>
> </li>
> </xsl:when>
>
> <xsl:when test="local-name() = 'step'">
> <xsl:variable name="step_idref"
> select="current()" />
> <li>
> <a><xsl:attribute name="href">
>
> <xsl:text>javascript:get_explanation('</xsl:text>
> <xsl:value-of
> select="$step_idref" />
> <xsl:text>');</xsl:text>
> </xsl:attribute>
> <xsl:value-of
> select="//task[@id=$step_idref]/title"/>
> </a>
> </li>
> </xsl:when>
> </xsl:choose>
> </xsl:for-each>
> </ol>
> </xsl:when>
>
> <xsl:when test="@task_type='discrete'">
> <a><xsl:attribute name="href">
>
> <xsl:text>javascript:get_explanation('</xsl:text>
> <xsl:value-of select='@id' />
> <xsl:text>');</xsl:text>
> </xsl:attribute>
> <xsl:value-of select="title"/>
> </a>
> </xsl:when>
>
> </xsl:choose>
> </xsl:template>
>
>
> <!-- This template is used to retrieve the contents of
> the <task_text>
> element of the <task> with the @id that matches the
> value provided in
> the $selected.task.id param. The contents of a
> single <task_text>
> element should be returned.
> -->
> <xsl:template match="task" mode="task_desc">
> <xsl:value-of select="task_text" />
> </xsl:template>
>
> </xsl:stylesheet>
>
-
[XOM-interest] XSLTransform,
Jacobs, Robert A., 03/30/2005
- RE: [XOM-interest] XSLTransform, Michael Kay, 03/31/2005
- <Possible follow-up(s)>
-
RE: [XOM-interest] XSLTransform,
Jacobs, Robert A., 03/31/2005
- RE: [XOM-interest] XSLTransform, Michael Kay, 03/31/2005
-
RE: [XOM-interest] XSLTransform,
Jacobs, Robert A., 03/31/2005
- RE: [XOM-interest] XSLTransform, Michael Kay, 03/31/2005
- RE: [XOM-interest] XSLTransform, Jacobs, Robert A., 03/31/2005
- RE: [XOM-interest] XSLTransform, Jacobs, Robert A., 03/31/2005
Archive powered by MHonArc 2.6.24.