I have the following XML, which I need to extract the param value based on a child node attribute using XSLT. In this case extract a list of the activities my students are part of:
XML
<students>
<student id="1000020001"/>
<student id="1000020002"/>
</students>
<activities>
<activity name="yoga beginners" start="2016-10-12" end="2016-12-17">
<members>
<member id="1000020001"/>
</members>
</activity>
<activity name="yoga intermediate" start="2017-10-12" end="2017-12-17">
<members>
<member id="1000020001"/>
<member id="1000020002"/>
</members>
</activity>
</activities>
I want to create an XSLT which display the activities my students are part of, in this case I have:
XSLT For each student:
<xsl:for-each select="/activities/activity">
<b>Activity:</b>:
<xsl:call-template name="extractActivities">
<xsl:with-param name="student-id" select="@id"/>
</xsl:call-template>
</xsl:for-each>
<xsl:template name="extractActivities">
<xsl:param name="student-id"/>
<xsl:if test="$student-id = /activities/activity/members/member/@id">
<xsl:value-of select="@name"/>
</xsl:if>
</xsl:template>
I have the following two problems:
- First XSLT displays "Activity:" twice as is doing the loop for each node.
- No activity name is displayed
It is best to resolve cross-references by using a key:
XSLT 1.0
Applied to the following well-formed input:
XML
the result will be: