xsl-list
[Top] [All Lists]

Re: Conditional extraction of data

2004-11-09 10:05:16
Geert,

At 04:18 AM 11/9/2004, you wrote:
Bradley, Peter wrote:

Of course! To simply pass through all the content in the data file, all I need is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
</xsl:stylesheet>
The recursive processing; the default templates; these will take care of the rest.

Depends on what you mean by content. The default templates preserve the character data of the data file. Note that this includes character data in attributes, though you are not using them currently.

Unless I mistake your meaning: almost but not quite.

The default template for attributes, it is true, is

<xsl:template match="attribute::*">
  <xsl:value-of select="self::node()"/>
</xsl:template>

But, as you also know, the default template for elements is (again using long syntax for clarity):

<xsl:template match="child::*">
  <xsl:apply-templates select="child::node()"/>
</xsl:template>

... and since attributes must, perforce, be reached via their parent elements, but they are not children of those parents (they have been disinherited and don't get invited to holiday dinners except by special invitation), they are not selected by the apply-templates here.

Consequently, the data content of attributes *would* come through, but does not, since no attribute is ever selected for processing by default. (Try it and see.)

This interesting feature of the data model (attributes have parents but are not children; you need to use the attribute:: axis to reach them) is one of several examples of how XSLT's designers were subtle -- perhaps too subtle in some respects -- designing a system that works exactly the way you usually would want, but not for exactly the reasons you might guess. In this case, the default traversal and built-in templates are designed to result in clean handling of exactly the kind of data Peter has: heterogeneous structures with arbitrarily mixed content, in which attributes are relegated to a "support" role, such as is typical in document-oriented XML.

 Comments, processing-instructions and 'tags' are suppressed by default.

Tags, as David C constantly reminds us, are not even present in the data model.

Comments and PIs are selected by default (they come back from "child::node()"), but as you suggest, their built-in templates are empty (no value gets added to the tree as with text nodes or attributes), so they are suppressed.

Thanks for being the straw man here: of course, I'm not really writing for you but for all our newbie friends, whose mothers (for whatever reprehensible reasons) neglected to provide them with XSLT instruction in the womb.

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================



<Prev in Thread] Current Thread [Next in Thread>