Re: Key()

Subject: Re: Key()
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Wed, 28 Jun 2000 14:21:38 +0100

Rhonda Fischer wrote:
> 
> Thank you very much Jeni and Francis for your help.
> I really appreciated your friendly response. I am still
> grappling with some aspects of the problem.
> 
Thanks - even if I do feel a bit of a fraud appearing in the same
sentence as Jeni...

I think the new data structure with the un-nested Target elements is
simpler, and I would suggest a solution like this:

t1.xml
------
<Template>
    <Destination>
         <Target doc="contract"/>
          <Target doc="advice"/>
          <Target host="true"/>
          <Section><SectionHeading>My Heading
                                 </SectionHeading></Section>
          <Para>
               This paragraph appears in both the contract
                and advice documents and is only included
                for those customers hosting.
          </Para>
           <Para>
                Blah, Blah
           </Para>
    </Destination>
    <Destination>
        <Target doc="contract"/>
        <Target host="true"/>
         <Para>
              This paragraph will appear in only the contract
               document for those customers hosting.
          </Para>
          <Para>
              Blah
           </Para>
    </Destination>
</Template>
 

Now you can generate different documents by having different
stylesheets, which only need to vary in a single xpath expression.

For the contract document, try
contract.xsl
------------
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output indent="yes"/>

<xsl:template match="/">
  <Template>
    <xsl:for-each select="//Destination[Target/@doc='contract' and
Target/@host='true']/*">
      <xsl:choose>
        <xsl:when test="name()='Section'">
          <xsl:copy-of select="."/>
        </xsl:when>
        <xsl:when test="name()='Para'">
          <xsl:copy-of select="text()"/>
        </xsl:when>
      </xsl:choose>
    </xsl:for-each>
  </Template>
</xsl:template>

</xsl:stylesheet>    

For the advice doc, use:
advice.xsl
----------
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output indent="yes"/>

<xsl:template match="/">
  <Template>
    <xsl:for-each select="//Destination[Target/@doc='advice' and
Target/@host='true']/*">
      <xsl:choose>
        <xsl:when test="name()='Section'">
          <xsl:copy-of select="."/>
        </xsl:when>
        <xsl:when test="name()='Para'">
          <xsl:copy-of select="text()"/>
        </xsl:when>
      </xsl:choose>
    </xsl:for-each>
  </Template>
</xsl:template>

</xsl:stylesheet>

You'll see that the only difference between them is that 'contract' has
been replaced with 'advice'.

These select the right paragraphs when I run them in Saxon -

Francis.

-- 
Francis Norton.

Defy Convention? Deify Convention!


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


Current Thread