Sono bloccato con un piccolo problema.Riferimento a una variabile XSLT tramite un nome dinamico
Il XSL-File:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:template match="/">
<xsl:variable name="unumericValue" select="10" />
<xsl:variable name="uanotherValue" select="8" />
<xsl:for-each select="/root/try">
<xsl:value-of select="var" />
<xsl:variable name="min"><xsl:value-of select="@minimum" /></xsl:variable>
<xsl:value-of select="@type" />
<xsl:variable name="referenceName"><xsl:value-of select='concat("u",var)' /></xsl:variable>
<xsl:value-of select="$referenceName" />
<xsl:if test='$referenceName > $min'>
<p>Do something.</p>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
file XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="q1.xsl"?>
<root>
<try type="compare" minimum="9">
<var>numericValue</var>
<something>...</something>
</try>
<try type="compare" minimum="10">
<var>anotherValue</var>
<something>...</something>
</try>
</root>
Come si può vedere il file XML ha due var-elementi che dovrebbero corrispondere alle variabili in XSLT-File . Tuttavia non so quale sintassi sia corretta. $ referenceName è solo il nome della variabile che voglio usare. Ma non so come fare riferimento al nome della variabile esistente.
Grazie mille. Il primo suggerimento ha funzionato alla grande per me. – eadrax