0

两个问题:

  1. 如何根据完美匹配的 id 将第一个与另一个对应的链接联系起来?XML 源示例:

    <DIV>

    <div id="fr">

    <seg id="fr_1">abc</seg>
    <seg id="fr_2">def</seg>
    <seg id="fr_3">ghi</seg>
    <seg id="fr_4">jkl</ seg>
    <seg id="fr_5">mno</seg>
    </div>
    <div id="en">
    <seg id="en_1">AAA</seg>
    <seg id="en_2">BBB< /seg>
    <seg id="en_3">CCC</seg>
    <seg id="en_4">DDD</seg>
    <seg id="en_5">EEE</seg>
    </div>
    </DIV>

  2. 如何根据使用@corresp 建立的链接来链接来自两个或多个 div 的段?XML 源示例:

    <?xml 版本="1.0" 编码="ISO-8859-1"?>

    <DIV>

    <div id="fr">

    <seg id="fr_1" corresp="#en_1">abc</seg>
    <seg id="fr_2" corresp="#en_2 #en3">def</seg>
    <seg id="fr_3" corresp=" #en_3 #en_4">ghi</seg>
    <seg id="fr_4" corresp="#en_4 #en_5">jkl</seg>
    <seg id="fr_5" corresp="#en_6">mno</seg >
    </div>
    <div id="en">
    <seg id="en_1" corresp="#fr_1">ab</seg>
    <seg id="en_2" corresp="#fr_1 #fr_2">cde< /seg>
    <seg id="en_3" corresp="#fr_2 #fr_3">fg</seg>
    <seg id="en_4" corresp="#fr_3 fr_4">hij</seg>
    <seg id="en_5" corresp="#fr_4">kl</seg>
    <seg id="en_6" corresp="#fr_5 ">mno</seg>
    </div>
    </DIV>

感谢帮助。

4

1 回答 1

0

这是一个分组问题,使用 XSLT 1.0,您可以使用 Muenchian 分组http://www.jenitennison.com/xslt/grouping/muenchian.xml解决它;这样 XSLT

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xs">

<xsl:output method="html" indent="yes"/>

<xsl:key name="id" match="seg" use="substring-after(@id, '_')"/>

<xsl:template match="DIV">
  <xsl:copy>
    <ol>
      <xsl:apply-templates select="div/seg[generate-id() = generate-id(key('id', substring-after(@id, '_'))[1])]"/>
    </ol>
  </xsl:copy>
</xsl:template>

<xsl:template match="seg">
  <li>
    <xsl:apply-templates select="key('id', substring-after(@id, '_'))" mode="list"/>
  </li>
</xsl:template>

<xsl:template match="seg" mode="list">
  <xsl:if test="position() > 1">, </xsl:if>
  <xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>

转换输入

<DIV>

    <div id="fr">

        <seg id="fr_1">abc</seg>
        <seg id="fr_2">def</seg>
        <seg id="fr_3">ghi</seg>
        <seg id="fr_4">jkl</seg>
        <seg id="fr_5">mno</seg>
        </div>
        <div id="en">
        <seg id="en_1">AAA</seg>
        <seg id="en_2">BBB</seg>
        <seg id="en_3">CCC</seg>
        <seg id="en_4">DDD</seg>
        <seg id="en_5">EEE</seg>
        </div>
        </DIV>

进入输出

<DIV>
   <ol>
      <li>abc, AAA</li>
      <li>def, BBB</li>
      <li>ghi, CCC</li>
      <li>jkl, DDD</li>
      <li>mno, EEE</li>
   </ol>
</DIV>
于 2013-07-10T09:55:54.623 回答