xsl-list
[Top] [All Lists]

RE: How to filter element values...

2004-02-10 17:56:50
I could be reading it wrong, but I don't think that section covers the behavior 
that I am seeing. The built-in template calls <xsl:apply-templates mode="m"/>, 
"which allows recursive processing to continue in the same mode". I wouldn't 
expect the built-in text() and attribute template to apply to every mode, at 
least I don't see that described in the spec...

I would expect this stylesheet:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >
  <xsl:template match="/">
        <MISSING_MODE>
        <xsl:apply-templates mode="MISSING_MODE"/>
        </MISSING_MODE>
  </xsl:template>
</xsl:stylesheet>

to output:

<MISSING_MODE>
</MISSING_MODE>

and not:

<MISSING_MODE>
... all of the text nodes in the xml document ...
</MISSING_MODE>


Both Xalan and Saxon behave as though there is a built-in text and attribute 
template that is equivalent to:

<xsl:template match="text()|@*" mode="m">
  <xsl:value-of select="."/>
</xsl:template>

Josh

***************************
Subject: RE: [xsl] How to filter element values...
From: Wendell Piez <wapiez(_at_)xxxxxxxxxxxxxxxx>
Date: Sat, 07 Feb 2004 00:17:19 -0500
Josh,

There are defaults that apply to each mode, also, as described in the XSLT Rec, 
section 5.8:


There is also a built-in template rule for each mode, which allows recursive 
processing to continue in the same mode in the absence of a successful pattern 
match by an explicit template rule in the stylesheet. This template rule 
applies to both element nodes and the root node. The following shows the 
equivalent of the built-in template rule for mode m.


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


I hope this fills it in for you --


Cheers,
Wendell

-----Original Message-----
From: Josh Canfield 
Sent: Friday, February 06, 2004 4:43 PM
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: RE: [xsl] How to filter element values...


It looks like the <xsl:apply-templates mode="g"/> at the bottom of the Global 
template is causing the default template to get invoked.

Adding a new empty template

  <xsl:template match="Global/text() | EVENT/text()" mode="g"/>

Will fixes the problem.

I'm not sure why the default template is being invoked in this case. I read 
both http://www.w3.org/TR/xslt#modes and 
http://www.w3.org/TR/xslt#built-in-rule and they seem to be saying that only 
templates with a matching mode will be invoked. The 

Can anyone explain why this is happening?

Josh

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of 
Kotes Mogili
Sent: Friday, February 06, 2004 12:25 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] How to filter element values...


Hi,

I am using XSL to generate another XSL file from an XML file. I am interested 
in only Element names and attributes but not it's values. for the following XML 


<SiebelMessage>
<Global param="A" name="Y">aaaaa</Global>
<Global type="if" name="A" select="abcd">bbbb</Global>
<Global type="when" name="Y" select="ccc" otherwise="bbbbb">ccccc</Global>

<EVENT spec="IDL:sciOmSiebelEvents/RouterToOmServer:1.0#OrderCopyEvent\">
 ddddd
</EVENT>
</SiebelMessage>

I am getting the output as 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:preserve-space elements=""/>
    <xsl:strip-space elements="*"/>
    <xsl:param name="A"/>

 aaaaa 

<xsl:variable name="A">
        <xsl:value-of select="abcd"/>
    </xsl:variable>

 bbbb 

<xsl:variable name="Y">
        <xsl:choose>
            <xsl:when test=" ">
                <xsl:value-of select=" ccc"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select=" bbbbb"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

 ccccc ddddd 

<xsl:template match="*"/>
    <xsl:template match="SiebelMessage"/>
    <!-- End of SiebelMessage -->
</xsl:stylesheet>


I am not sure why the element values are coming when i am not refering it them. 
Any suggestions are greatly appreciated..


Thanks

kotes


<!-- *******************  XSL file  ********************** -->

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="text"/>
<xsl:strip-space elements="*" />   
<xsl:template match="/">
        &lt;xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0"&gt;
        &lt;xsl:output method="xml"  encoding="UTF-8" indent="yes"/&gt;
        &lt;xsl:preserve-space elements=""/&gt;
        &lt;xsl:strip-space elements="*"/&gt;
        <xsl:apply-templates select="*[Global]" mode="g"/>
        &lt;xsl:template match="*"&gt;
        &lt;/xsl:template&gt;
        &lt;xsl:template match="SiebelMessage"&gt;
     <!--  <xsl:apply-templates select="SiebelMessage"/>  -->
        <!-- &lt;/xsl:element &gt;-->
        &lt;/xsl:template &gt; &lt;!-- End of SiebelMessage --&gt;
     <!--    <xsl:apply-templates select="*" mode="t" />  -->
        &lt;/xsl:stylesheet&gt;
 </xsl:template>

<xsl:template match="SiebelMessage">
         <xsl:apply-templates select="EVENT"/>
</xsl:template>

<xsl:template match="EVENT">
                 &lt;xsl:element name=&quot;<xsl:value-of 
select="name()"/>&quot;&gt;
                 &lt;xsl:attribute name="spec"&gt;<xsl:value-of 
select="@spec"/>&lt;/xsl:attribute&gt;
                 <xsl:apply-templates/>
                 &lt;/xsl:element &gt;
</xsl:template>

<xsl:template match="Global"  mode="g">
   <xsl:if test="@type='if'">
              &lt;xsl:variable name="<xsl:value-of select="@name"/>"&gt;
                <xsl:if test="@select"> &lt;xsl:value-of select="<xsl:value-of 
select="@select"/>"/&gt;</xsl:if>
                <xsl:if test="@hardcode">&lt;xsl:text&gt;<xsl:value-of 
select="@hardcode"/>&lt;/xsl:text&gt;</xsl:if>
              &lt;/xsl:variable&gt;
     </xsl:if>
     <xsl:if test="@param">
               &lt;xsl:param name="<xsl:value-of select="@param"/>"/&gt;        
 
     </xsl:if>
            <xsl:if test="@type='when' ">
                &lt;xsl:variable name="<xsl:value-of select="@name"/>"&gt;
                &lt;xsl:choose&gt;
                &lt;xsl:when test=&quot; <xsl:value-of 
select="@gtest"></xsl:value-of>&quot;&gt;
                    <xsl:if test="@select">&lt;xsl:value-of select=&quot; 
<xsl:value-of select="@select"/>&quot;/&gt;</xsl:if>
                    <xsl:if test="@sHardcode">&lt;xsl:text&gt;<xsl:value-of 
select="@sHardcode"/>&lt;/xsl:text&gt;</xsl:if>
                 &lt;/xsl:when &gt;
                 &lt;xsl:otherwise&gt;
                     <xsl:if test="@otherwise">&lt;xsl:value-of select=&quot; 
<xsl:value-of select="@otherwise"/>&quot;/&gt;</xsl:if>
                     <xsl:if test="@oHardcode">&lt;xsl:text&gt;<xsl:value-of 
select="@oHardcode"/>&lt;/xsl:text&gt;</xsl:if>
                 &lt;/xsl:otherwise&gt;
                 &lt;/xsl:choose&gt;
                 &lt;/xsl:variable&gt;
     </xsl:if>
     <xsl:apply-templates mode="g"/>
</xsl:template>

 </xsl:stylesheet>

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


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



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