The following XPath will select the discussion attribute type = "foo" and containing the text "T50 as Discussion" (at $ topicid = 50).
//discussions/discusson[@type='foo' and contains(., concat('T', $topicid, ' as Discussion ')]
For a particular discussion item, the corresponding identifier is defined as follows:
substring-after(normalize-space(.),' as Discussion ')
We can combine 2 by replacing ".". in the second expression with all the first expression. Please note that if several discussions coincide with the internal expression, we will concatenate their values ββfrom the second.
substring-after(normalize-space( //discussions/discusson[@type='foo' and contains(., concat('T', $topicid, ' as Discussion ')] ),' as Discussion ')
If there have been several overlapping discussions, you can process them as follows:
<xsl:for-each select="//topics/topic"> <xsl:variable name="topicid" select="@id" /> <xsl:for-each select="//discussions/discusson[@type='foo' and contains(., concat('T', $topicid, ' as Discussion ')]"> <xsl:variable name="relatedid" select="substring-after(normalize-space(.),' as Discussion ')" /> <!-- do something with $topicid and $relatedid --> </xsl:for-each> </xsl:for-each>
Function Links:
Personally, I canβt imagine how XSLT is seriously developing without the book by Michael Kay.
source share