Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "Wasiq Shaikh" <wasiq911@----------->
To:
Date: 8/1/2007 6:55:00 PM
Ah, I see! When I printed the variable it "looked" like a nodeset, so I 
assumed I could access the elements and attributes within.



This is my working solution after applying Mukul's suggestion. Thanks Mukul!



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

     <xsl:if test="$validAttributeType!=''">

        <xsl:element name="validValues">

           <xsl:call-template name="trimAttribute">

              <xsl:with-param name="attributeName" select="'base'"/>

              <xsl:with-param name="attribute" 
select="xalan:nodeset($validAttributeType)/*/@base"/>

           </xsl:call-template>

           <xsl:for-each select="xalan:nodeset($validAttributeType)/*/*">

              <xsl:element name="value">

                 <xsl:attribute name="type">

                    <xsl:value-of select="substring-after(name(), 
'xsd:')"/>

                 </xsl:attribute>

                 <xsl:value-of select="@value"/>

              </xsl:element>

           </xsl:for-each>

        </xsl:element>

     </xsl:if>



(using XalanJ 2.7/XPath 1.0)




----Original Message Follows----



The error you are getting at this line, <xsl:with-param
name="attribute" select="$validAttributeType/@base"/>

is because the variable "validAttributeType" is a result tree fragment
(it's a special data type defined in XSLT 1.0), and you are trying to
apply an XPath operation to it; which is not correct.

To my opinion, you need to use an extension function node-set for this
(if you are restricted to XSLT 1.0).

So for example, something like following will work:
<xsl:with-param name="attribute"
select="xx:node-set($validAttributeType)/xsd:restriction/@base"/>

(please bind the prefix xx to the required namespace - please see the
product documentation for this)

With XSLT 2.0, you will not get the error at all, for the operation
you are trying to do (because XSLT 2.0 implicitly treats the contents
of xsl:variable in this case as a node-set).

On 8/1/07, Wasiq Shaikh <wasiq911@xxxxxxxxxxx> wrote:

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




--
Regards,
Mukul Gandhi

_________________________________________________________________

Reconnect with Familiar Faces with Windows Live Spaces 
http://spaces.live.com/?mkt=en-ca


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent