[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Key()

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

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.