Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Xslt使用不同语言的不同规则在字符串之间获取文本_Html_Xml_Xslt_Html Parsing - Fatal编程技术网

Html Xslt使用不同语言的不同规则在字符串之间获取文本

Html Xslt使用不同语言的不同规则在字符串之间获取文本,html,xml,xslt,html-parsing,Html,Xml,Xslt,Html Parsing,我正在使用xslt解析Html页面。 在页面上有一个和平的html,我想从中获得出版商的名字 <div> <span class="publisher_name">by xxx from TripAdvisor</span> </div> xslt返回string.Empty,因为它无法按string查找 所以我想添加类似的规则来支持西班牙语字符串 <xsl:with-param name="string" select="subs

我正在使用xslt解析Html页面。 在页面上有一个和平的html,我想从中获得出版商的名字

<div>
    <span class="publisher_name">by xxx from TripAdvisor</span>
</div>
xslt返回string.Empty,因为它无法按string查找

所以我想添加类似的规则来支持西班牙语字符串

<xsl:with-param name="string" select="substring-before(substring-after($publisherTextNode, 'por'), 'de')" />
我是否可以将这两条规则添加到现有xslt模式中,或者检查第一条规则是否返回string.Empty,然后使用第二条规则?还是为不同的语言创建一个单独的


类似XSLT 1.0的东西怎么样:

<xsl:call-template name="string-trim">
    <xsl:with-param name="string">
        <xsl:choose>
            <xsl:when test="contains($publisherTextNode, 'by ') and contains($publisherTextNode, ' from')">
                <xsl:value-of select="substring-before(substring-after($publisherTextNode, 'by '), ' from')" />
            </xsl:when>
            <xsl:when test="contains($publisherTextNode, 'por ') and contains($publisherTextNode, ' de')">
                <xsl:value-of select="substring-before(substring-after($publisherTextNode, 'por '), ' de')" />
            </xsl:when>
        </xsl:choose>
    </xsl:with-param>
</xsl:call-template>

请注意,测试中出现假阳性的可能性很小。

Thx,它正在工作。。。但是,注意事项很重要如果您的示例是指示性的,您可以通过使用starts-with替换第一个条件中的contains来减少这种可能性。另外,这也可以使用xquery来完成。
<xsl:with-param name="string" select="substring-before(substring-after($publisherTextNode, 'por'), 'de')" />
  <xsl:template name="string-trim">
<xsl:param name="string" />
<xsl:param name="trim" select="$whitespace" />
<xsl:call-template name="string-rtrim">
  <xsl:with-param name="string">
    <xsl:call-template name="string-ltrim">
      <xsl:with-param name="string" select="$string" />
      <xsl:with-param name="trim"   select="$trim" />
    </xsl:call-template>
  </xsl:with-param>
  <xsl:with-param name="trim"   select="$trim" />
</xsl:call-template>
<xsl:template name="string-ltrim">
<xsl:param name="string" />
<xsl:param name="trim" select="$whitespace" />

<xsl:if test="string-length($string) &gt; 0">
  <xsl:choose>
    <xsl:when test="contains($trim, substring($string, 1, 1))">
      <xsl:call-template name="string-ltrim">
        <xsl:with-param name="string" select="substring($string, 2)" />
        <xsl:with-param name="trim"   select="$trim" />
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:if>
  <xsl:template name="string-rtrim">
<xsl:param name="string" />
<xsl:param name="trim" select="$whitespace" />

<xsl:variable name="length" select="string-length($string)" />

<xsl:if test="$length &gt; 0">
  <xsl:choose>
    <xsl:when test="contains($trim, substring($string, $length, 1))">
      <xsl:call-template name="string-rtrim">
        <xsl:with-param name="string" select="substring($string, 1, $length - 1)" />
        <xsl:with-param name="trim"   select="$trim" />
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:if>
<xsl:call-template name="string-trim">
    <xsl:with-param name="string">
        <xsl:choose>
            <xsl:when test="contains($publisherTextNode, 'by ') and contains($publisherTextNode, ' from')">
                <xsl:value-of select="substring-before(substring-after($publisherTextNode, 'by '), ' from')" />
            </xsl:when>
            <xsl:when test="contains($publisherTextNode, 'por ') and contains($publisherTextNode, ' de')">
                <xsl:value-of select="substring-before(substring-after($publisherTextNode, 'por '), ' de')" />
            </xsl:when>
        </xsl:choose>
    </xsl:with-param>
</xsl:call-template>