2 に答える
2
より一般的なアプローチは、次のようなテンプレートを定義することです。
<xsl:template name="GetPIAttribute">
<xsl:param name="pi" />
<xsl:param name="attrName" />
<xsl:variable name="toFind" select="concat(' ', $attrName, '=')"/>
<xsl:variable name="piAdjusted" select="concat(' ', normalize-space($pi))"/>
<xsl:variable name="foundMatch" select="substring-after($piAdjusted, $toFind)" />
<xsl:if test="$foundMatch">
<xsl:variable name="delimiter" select="substring($foundMatch, 1, 1)" />
<xsl:value-of select="substring-before(substring-after($foundMatch, $delimiter), $delimiter)"/>
</xsl:if>
</xsl:template>
次に、これを呼び出して、次のように、必要な疑似属性を取得できます。
<xsl:template match="/">
<xsl:call-template name="GetPIAttribute">
<xsl:with-param name="pi" select="/processing-instruction()[name() = 'table']" />
<xsl:with-param name="attrName" select="'name'" />
</xsl:call-template>
</xsl:template>
このアプローチの利点は、一重引用符または二重引用符で囲まれた値を考慮し、複数の値を抽出する必要がある場合に再利用できることです。
于 2013-01-17T10:59:52.277 に答える
0
それは実際には属性ではありません。これは、処理命令の値にすぎません。
値を取得する唯一の方法は、文字列を操作することだと思います...
<xsl:template match="processing-instruction()[name()='table']">
<xsl:value-of select="substring-before(substring-after(.,'name="'),'"')"/>
</xsl:template>
于 2013-01-17T09:49:22.460 に答える