Subject: [xsl] select elements based on another element's attributes From: "Lars Nyman" <larsnyman@xxxxxxxxxxxxx> Date: Wed, 24 Jul 2002 13:22:15 -0700 |
Assume a widget element with some attr elements that defines some attributes of a widget: <widget widget-id="402"> <attrs> <attr name="p1" public="true"/> <attr name="p2" public="true"/> <attr name="p3" public="false"/> <attr name="p4" public="true"/> </attrs> </widget> A widget-ref element may refer to the above widget element. The widget-ref specify values for some of the attributes of the widget using attributes named according to the attr/@name of the widget. <widget-ref widget-id="402" p1="v1" p2="v2" p3="v3" p5="v5"/> During processing, I would like to select all the attr elements of the widget that have a "corresponding" attribute in the widget-ref element. Alternatively, I would like to select all the attributes of the widget-ref elements that have a "corresponding" attr element in the widget element. With "corresponding" I mean that the widget-ref attribute name is equal to the attr/@name, and as an additional constraint, the attr/@public must be "true". I intend to iterate over the attributes and emit name/value pairs. For the widget-ref element above I want to emit: p1=v1,p2=v2 Note: p3=v3 is not emitted because the "corresponding" attr element with @name="p3" has @public="false" p5=v5 is not emitted because there is no "corresponding" attr element with @name="p5" So, I am looking for a select expression to use in place of either EXPR1 or EXPR2 in the template below. <xsl:template name="process-widget-ref"> <xsl:param name="widget-ref"/> <xsl:param name="widget"/> <-- if iterating over widget-ref attributes --> <xsl:for-each select="EXPR1"> <xsl:value-of select="name()"/>=<xsl:value-of select="."/> <xsl:if test="position()!=last()">,</xsl:if> </xsl:for-each> <-- if iterating over widget/attrs/attr elements --> <xsl:for-each select="EXPR2"> <xsl:value-of select="@name"/>=<xsl:value-of select="$widget-ref/@*[name()=name(current())]"/> <xsl:if test="position()!=last()">,</xsl:if> </xsl:for-each> </xsl:template> My initial attempt for EXPR2 $widget/attrs/attr[@name=name($widget-ref/@*) and @public='true'] does not work since name($widget-ref/@*) returns the name of the first node only. Lars XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Acheiving ..2nd level gro, KUMAR NINGASHETTY | Thread | Re: [xsl] select elements based on , Jeni Tennison |
Re: [xsl] math get maximum and subt, sascha | Date | [xsl] ANN: Browser based XML editor, James Fuller |
Month |