I have a parameterignoreAttributes
which is a comma separated list of things to look for. I want to set a variable copyAttrib
to be equal to whether any of them are exactly matched by name()
.
If xsl
were a procedural language where variables could be reassigned, I'd use something like this:
<xsl:variable name="copyAttrib" select="true()">
<xsl:for-each select="tokenize($ignoreAttributes,',')">
<xsl:if test="compare(., name()) != 0">
<xsl:variable name="copyAttrib" select="false()"/>
</xsl:if>
</xsl:for-each>
Unfortunately, I can't do that, because xsl
is functional (so says this other answer). So variables can only be assigned once.
I think the solution would look something like:
<vsl:variable name="copyAttrib">
<xsl:choose>
<xsl:when>
<xsl:for-each select="tokenize($ignoreAttributes, ',')">
<xsl:if test="compare(., name()) != 0"/>
</xsl:for-each>
<xsl:otherwise>
<xsl:value-of select="false()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Obviously not exactly that (otherwise I wouldn't be asking.)
I know that I could bypass the tokenize
and for-each
loop by just using replaces
on ignoreAttributes and changing all the ,
to |
and then using matches
, but I'd like to avoid that if possible because then I need to deal with the possibility that ignoreAttributes
(which the user provides) might contain some special characters that will change the regex pattern and escape them all.