1
4

3 回答 3

0

像这样尝试:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

    <xsl:template match="div">
        <xsl:element name="div">
            <xsl:value-of select="normalize-space(a/text()[1])"/>
            <xsl:value-of select="(.//span/span[@class='nu'])[1]/text()"/>
            <xsl:value-of select="normalize-space(a/text()[2])"/>
            <xsl:value-of select="(.//span/span[@class='nu'])[2]/text()"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

我假设<div>已正确关闭:)。

于 2012-08-22T09:27:13.277 回答
0

您可能想要创建一个参数来保存“nu”值。

<xsl:param name="lang" select="'nu'" />

然后,您将能够像这样提取特定于语言的文本

<xsl:template match="span[@class='languageSpecificText']">
   <xsl:value-of select="span[@class=$lang]" />
</xsl:template>

这是完整的 XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="html"/>

   <xsl:param name="lang" select="'nu'" />

   <xsl:template match="a">
      <xsl:apply-templates />
   </xsl:template>

   <xsl:template match="span[@class='languageSpecificText']">
      <xsl:value-of select="span[@class=$lang]" />
   </xsl:template>

   <xsl:template match="a/text()">
      <xsl:value-of select="normalize-space()" />
   </xsl:template>

   <xsl:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

应用于您的示例 XML 时,将输出以下内容

<div>Swap(T)</div>

将参数更改为'vb',您会得到以下信息

<div>Swap(Of T)</div>
于 2012-08-22T09:42:30.837 回答
0
于 2012-08-22T12:44:56.097 回答