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

Attribute Handling

Subject: Attribute Handling
From: Christian Lindig <lindig@xxxxxxxxxxxxxxx>
Date: Thu, 8 Oct 1998 16:49:37 +0200
xsl process attributes
I just have started to explore XML and thus my question may be a FAQ:

(1) How do I write a template that matches optional attributes such
    that I have access to the values of the attributes? Let's look at the
    HTML IMG element:

        <!ELEMENT IMG - O EMPTY                -- Embedded image -->
        <!ATTLIST IMG
          %attrs;                              -- %coreattrs, %i18n, %events --
          src         %URI;          #REQUIRED -- URI of image to embed --
          alt         %Text;         #REQUIRED -- short description --
          longdesc    %URI;          #IMPLIED  -- link to long description
                                                  (complements alt) --
          height      %Length;       #IMPLIED  -- override height --
          width       %Length;       #IMPLIED  -- override width --
          usemap      %URI;          #IMPLIED  -- use client-side image map --
          ismap       (ismap)        #IMPLIED  -- use server-side image map --

   The following template will only match elements where certain
   attributes are present. Am I forced to write a template for every
   possible combination of attributes if I want to make use of the
   present attributes?

        <xsl:template match="img[attribute(src),
          <img src="{attribute(src)}"
        <xsl:template match="img[attribute(src),
          <img src="{attribute(src)}"

Related to the problem above I would like to make a suggestion.  

(2) The template above just passes the element together with all its
    attributes matched. It would be convenient to have something like the
    built-in template rule available for this:

        <!-- standard rule -->
        <xsl:template match="*">
        <!-- suggested rule -->
        <xsl:template match="*">

   <xsl:insert-match-and-process-children/> does what
   <xsl:process-children/> does, but inserts the result of
   <xsl:process-children/> into an element that was just matched
   including all its attributes (instead of forgetting what was just
   matched like the standard rule does). This would allow to write a
   single rule for all elements that are just passed through XML and
   concentrate on the elements that need non trivial processing. This way
   XML could be used to implement new elements for existing DTDs by
   translating the new elements to the existing ones. Only rules for the
   new elements would be needed and all other ones would be matched by
   the suggested rule.

-- Christian

Christian Lindig                  http://www.cs.tu-bs.de/softech/people/lindig 
                                  mail:  lindig@xxxxxxxxxxxxxxx  

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

Current Thread


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.
First Name
Last Name
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.