Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

XSLT Question (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: [BUG] Using realSQLdatabase with a UB or Intel build crashes the app
Next thread: Getting user name/privilege level and admin name


FW: Special Valentine's Offer for Valentina - Beat the Price Increase!   -   Lynn Fredricks
  XSLT Question   -   Robert Fang
   Re: XSLT Question   -   Robert Fang

XSLT Question
Date: 04.08.07 19:36 (Sat, 04 Aug 2007 13:36:17 -0500)
From: Robert Fang
I am trying to query objects using an XML stylesheet using two variables...
One for the attribute name, and one for the attribute value. I have defined
the following variables, and verified that they return the expected value:

<xsl:variable name="attName" select="@NAME"/>
<xsl:variable name="attValue" select="@NAME"/>

attName references the name of a parent node, and attValue references the
name of a child node of the parent node. The name of the parent node exists
as an attribute of an object within the XML file, and the value of that
attribute for the object within the XML file can be any one of the names of
the child nodes.

The XML would look something like:

<object type="1st Type"/>
<object type="2nd Type"/>

In this example attName would be "type", and attValue would be either "1st
Type" or "2nd Type".

What I am trying to accomplish is a count of the different values. In the
XSLT if I enter:

<xsl:value-of select="count(//object[@type='1st Type'])"/>

I get the proper value. Also, if I use the attValue variable, I get the
correct value. For example:

<xsl:value-of select="(//object[@type=$attValue)"/>

However, if I try to use the attName variable with the "@" symbol, I get an
XML exception when loading the stylesheet. For example:

<xsl:value-of select="(//object[@$attName=$attValue)"/> or
<xsl:value-of select="(//object[@$attName='1st Type')"/> or
<xsl:value-of select="(//object[@{$attName}=$attValue)"/>

If I remove the "@" symbol, the XML stylesheet will load without an error,
but I always get a count of zero. For example:

<xsl:value-of select="(//object[$attName=$attValue)"/> or
<xsl:value-of select="(//object[$attName='1st Type')"/>

I must not be constructing this statement correctly. Does anyone know of the
proper way to reference an attribute name using a variable?

Thanks,

Bob

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: XSLT Question
Date: 04.08.07 21:03 (Sat, 04 Aug 2007 15:03:16 -0500)
From: Robert Fang
I found the answer:

<xsl:value-of select="(//object[@*[name()=$attName]=$attValue)"/>

Thanks,

Bob

On 8/4/07 1:36 PM, "Robert Fang" <<email address removed>> wrote:

> I am trying to query objects using an XML stylesheet using two variables...
> One for the attribute name, and one for the attribute value. I have defined
> the following variables, and verified that they return the expected value:
>
> <xsl:variable name="attName" select="@NAME"/>
> <xsl:variable name="attValue" select="@NAME"/>
> attName references the name of a parent node, and attValue references the
> name of a child node of the parent node. The name of the parent node exists
> as an attribute of an object within the XML file, and the value of that
> attribute for the object within the XML file can be any one of the names of
> the child nodes.
>
> The XML would look something like:
>
> <object type="1st Type"/>
> <object type="2nd Type"/>
> In this example attName would be "type", and attValue would be either "1st
> Type" or "2nd Type".
>
> What I am trying to accomplish is a count of the different values. In the
> XSLT if I enter:
>
> <xsl:value-of select="count(//object[@type='1st Type'])"/>
> I get the proper value. Also, if I use the attValue variable, I get the
> correct value. For example:
>
> <xsl:value-of select="(//object[@type=$attValue)"/>
> However, if I try to use the attName variable with the "@" symbol, I get an
> XML exception when loading the stylesheet. For example:
>
> <xsl:value-of select="(//object[@$attName=$attValue)"/> or
> <xsl:value-of select="(//object[@$attName='1st Type')"/> or
> <xsl:value-of select="(//object[@{$attName}=$attValue)"/>
> If I remove the "@" symbol, the XML stylesheet will load without an error,
> but I always get a count of zero. For example:
>
> <xsl:value-of select="(//object[$attName=$attValue)"/> or
> <xsl:value-of select="(//object[$attName='1st Type')"/>
> I must not be constructing this statement correctly. Does anyone know of the
> proper way to reference an attribute name using a variable?
>
> Thanks,
>
> Bob
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>