xsl-list
[Top] [All Lists]

Re: [xsl] Built in templates and issues getting the XSLT processor to navigate an input document

2007-09-25 03:40:49
You are matching on Subject_Area_and_Entity_Groups from the http://www.ca.com/erwin/data namespace in your stylesheet while your instance document defines the Subject_Area_and_Entity_Groups element in no namespace. You may eventually want to change the instance as below or otherwise modify the stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<Subject_Area_and_Entity_Groups
  xmlns:UDP="http://www.ca.com/erwin/metadata";
  xmlns="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>
      </Subject_AreaProps>
    </Subject_Area>
  </Subject_Area_Groups>
</Subject_Area_and_Entity_Groups>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Dunk, Michael (Mike) wrote:
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.



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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