xsl-list
[Top] [All Lists]

RE: [xsl] Accessing attribute in a variable with conditional value

2007-08-01 12:03:06
Options:

(a) use XSLT 2.0

(b) failing that, use the xx:node-set() extension in 1.0

(c) get the value of the base attribute in both branches:

      <xsl:variable name="validAttributeTypeBase">
         <xsl:if test="key('allTypes', @type)">
            <xsl:copy-of select="key('allTypes',
@type)/xsd:restriction/@base"/>
         </xsl:if>
         <xsl:if test="xsd:simpleType"
            <xsl:copy-of select="xsd:simpleType/xsd:restriction/@base"/>
         </xsl:if>
      </xsl:variable>

(are they mutually exclusive, by the way?)

(d) use a union:

<xsl:variable name="validAttributeTypeBase"
  select="key('allTypes', @type)/xsd:restriction |
xsd:simpleType/xsd:restriction"/>

Option (d) was the last one I thought of but it seems to be the best choice.

Michael Kay
http://www.saxonica.com/

 

-----Original Message-----
From: Wasiq Shaikh [mailto:wasiq911(_at_)hotmail(_dot_)com] 
Sent: 01 August 2007 18:41
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Accessing attribute in a variable with 
conditional value

Hi,

I'm setting a value on a variable using conditions. The 
variable must be a node-set so that I can do some processing with it.

      <xsl:variable name="validAttributeType">
         <xsl:if test="key('allTypes', @type)">
            <xsl:copy-of select="key('allTypes', 
@type)/xsd:restriction"/>
         </xsl:if>
         <xsl:if test="xsd:simpleType"
            <xsl:copy-of select="xsd:simpleType/xsd:restriction"/>
         </xsl:if>
      </xsl:variable>

The "xsd:restriction" tag has a "base" attribute that I need 
to access and send to a template as a parameter.

            <xsl:call-template name="trimAttribute">
               <xsl:with-param name="attributeName" select="'base'"/>
               <xsl:with-param name="attribute" 
select="$validAttributeType/@base"/>
            </xsl:call-template>

But it gives me a "XSLT Error 
(javax.xml.transform.TransformerException): 
org.apache.xpath.objects.XRTreeFrag" when I try to do

<xsl:with-param name="attribute" select="$validAttributeType/@base"/>
OR
<xsl:with-param name="attribute"><xsl:copy-of 
select="$validAttributeType/@base"/></xsl:with-param>

I can print out the variable's contents, which is correct, 
but I can't seem to access the attribute. By the way, 
previously I had this

<xsl:variable name="validAttributeType" 
select="key('allTypes', @type)/xsd:restriction"/>

which works! But adding the conditional messed it up. How can 
I get the same behaviour as the above line in a conditional variable?

I appreciate any help. Thank you!

_________________________________________________________________
Show Your Messenger Buddies How You Really Feel
http://www.freemessengeremoticons.ca/?icid=EMENCA122


--~------------------------------------------------------------------
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>
--~--