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

Re: [XPath] matching elements which satisfy a specific

Subject: Re: [XPath] matching elements which satisfy a specific content model
From: Tobias Reif <tobiasreif@xxxxxxxxxxxxx>
Date: Mon, 13 Jan 2003 12:29:43 +0100
xsl get specific element 0
David Carlisle wrote:

> I find it's rare to ever need this kind of test though.
>
> If your input may include
>
> <variablelist>
>    <title></title>
> </variablelist>
>
>
> and
>
>
> <variablelist>
>    <title></title>
>    <varlistentry/>
> </variablelist>
>
>
> how do you want them to be processed?

see below

> If the first is an error you can arrange to dtd validate before
> transforming in which case such fragments will never get as far as
> XSLt
> so you don't need to check for them in the pattern.

I could rely on DTD validation, but I don't think I should. My template says what it matches, and thus states what it can handle: no matter what which version of which spec/schema(DTD etc) says.
It can handle this type of content model, nothing more. And if a future version of the schema allows for an extended content model, there will be no problem with validity in the oputput.


> If validation is not an option it's often simpler to match on the
> simpler * case but then have
> <xsl:if test="not(varlistentry)">...

I already have to test for the existence of the title.

> Do you really have a case where you want to accept both these things
> but
> teh reulting output is so different that you don't want to share a
> template for the two cases?

[very hackish draft of pseudo-code]
<t:template match="variablelist[]">
  <t:if test="title">
    <t:element name="h{count(ancestor::*)}">
      <t:value-of select="title"/>
    </t:element>
  </t:test>
  <dl>
    <t:apply-templates/>
  </dl>
</t:template>
<!-- quirky -->
<t:template match="variablelist[]/title"/>

In [], picture either a very long XPath1.0 thingy, or an elegant, short content-model description :)

But beware; sure there are many different ways to handle this, and none of them *requires* what I propose. But it would make some things simpler.

Tobi

--

Vim users               donate.
http://iccf-holland.org/donate.html

Web developers           check.
http://www.pinkjuice.com/check/


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.