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

Built in templates and issues getting the XSLT process

Subject: Built in templates and issues getting the XSLT processor to navigate an input document
From: "Dunk, Michael (Mike)" <mikedunk@xxxxxxxxxxxxx>
Date: Tue, 25 Sep 2007 05:11:46 -0500
 Built in templates and issues getting the XSLT process
Thanks again to Ken Holman and Wendell Piez for their response to my
previous posting.

To try and get a better understanding of the XSLT processing model and
built in templates, I have have read sections of Doug Tidwell's XSLT and
Jeni Tennison's Beginning XSLT 2.0: From Novice to Professional.

Then I ran a stylesheet without templates and a stylesheet that has only

a single template, which matches a single type of element deep in
the tree.

I think the following built in template for elements:

<xsl:template match="*">
  <xsl:apply-templates />
</xsl:template>

A match pattern of "*" matches all elements, ensuring the root node and
its children were processed.

Then the built-in template for text nodes ensured any text was output:

<xsl:template match="text()">
  <xsl:value-of select="." />
</xsl:template>

Recursive processing appeared to continue, even when there was no
template declared for an element.

Then I tried processing an input xml

<?xml version='1.0'?>
<a> Text a
  <b> Text b
    <c> Text c </c>
  </b>
  <x> Text x
    <y> Text y
      <z> Text z </z>
    </y>
  </x>
</a>

With the following stylesheet:

<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="c">
   <boo>
     <xsl:apply-templates/>
   </boo>
</xsl:template>

<xsl:template match="z">
   <bah>
     <xsl:apply-templates/>
   </bah>
</xsl:template>
</xsl:stylesheet>


The following was output:

<?xml version="1.0" encoding="UTF-8"?>
Text a
Text b
<boo> Text c </boo>
Text x
Text y
<bah> Text z </bah>


When the XSLT processor can't find a template to match the node that
it's been told to process, it uses a built-in template. So the
unexpected text a, b, x and y is due to built-in templates.

However, I am still having issues with getting the XSLT processor to
navigate an the input document to create a result.

Using a simple input document:

<?xml version='1.0'?>
<a> Text a
  <b> Text b
    <c> Text c </c>
  </b>
  <x> Text x
    <y> Text y
      <z> Text z </z>
    </y>
  </x>
</a>

A stylesheet to navigate to element c

<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
  <xsl:message> found root </xsl:message>
    <xsl:apply-templates select="a/b"/>
</xsl:template>

<xsl:template match="a/b">
  <xsl:message> b found </xsl:message>
    <xsl:apply-templates select="a/b/c"/>
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="a/b/c">
  <xsl:message> c found </xsl:message>
    <xsl:apply-templates/>

</xsl:template>
</xsl:stylesheet>

The XSLT processor sends the following messages:

Found root
b found
c found

Whereas when I attempt the same navigation using my xml
(here a the start of the source xml):

<?xml version="1.0" encoding="UTF-8"?>
<Subject_Area_and_Entity_Groups
xmlns:UDP="http://www.ca.com/erwin/metadata"

xmlns:EMX="http://www.ca.com/erwin/data">
   <Subject_Area_Groups xmlns="http://www.ca.com/erwin/data"
xmlns:EM2="http://www.ca.com/erwin/EM2data">
      <Subject_Area id="{39146A35-A713-4CAA-9FBF-9AA575FA9F44}+0000001F"
name="&lt;Main Subject Area&gt;">
         <Subject_AreaProps>
            <Built-in_Id>31</Built-in_Id>
            <Definition/>
            <Name>&lt;Main Subject Area&gt;</Name>
.
.
.

With the following xslt:

<?xml version='1.0'?>
<xsl:stylesheet version="2.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://www.ca.com/erwin/data">
<xsl:output method="xml" indent="yes"/>

<xsl:key name="entity-id"
match="Subject_Area_and_Entity_Groups/Entity_Groups/Entity" use="@id"/>

<xsl:template match="/">
  <xsl:message> root found </xsl:message>
  <xsl:apply-templates
select="Subject_Area_and_Entity_Groups/Subject_Area_Groups"/>
</xsl:template>

<xsl:template
match="Subject_Area_and_Entity_Groups/Subject_Area_Groups">
  <xsl:message> Subject_Area_Groups found </xsl:message>
  <Subject_Areas>
    <xsl:apply-templates select="Subject_Area"/>
  </Subject_Areas>
</xsl:template>

<xsl:template match="Subject_Area">
 <Subject_Area>
  <xsl:value-of select="@name"/>

  <xsl:for-each
select="Subject_AreaProps/Referenced_Entities_Array/Referenced_Entities"
>
    <included-table>
     <xsl:value-of select="key('entity-id', @id )"/>
    </included-table>
  </xsl:for-each>

 </Subject_Area>
</xsl:template>

</xsl:stylesheet>

The only message output by the XSLT processor is:

root found.

I was expecting to see:

root found
Subject_Area_Groups found


I would be interested to know if you have any comments on the above or
if you know how can the above results be explained?

Best regards,

Mike
This email and any files transmitted with it are confidential, proprietary
and intended solely for the individual or entity to whom they are addressed.
If you have received this email in error please delete it immediately.

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.