0

示例文件 1:

<root>
<tu creationdate="20130704T142811Z" changedate="20130704T142811Z" lastusagedate="20130704T142811Z">
  <prop type="x-Context">0, 0</prop>

  <tuv xml:lang="es-ES">
    <seg>Kit de aislamiento del ARN de tejido fijado en formol e incluido en parafina (FFIP)</seg>
  </tuv>
</tu>
<tu creationdate="20130704T142811Z" changedate="20130704T142811Z" lastusagedate="20130704T142834Z" usagecount="1">
  <prop type="x-Context">-2654973059922618556, -1379942944751394277</prop>

  <tuv xml:lang="es-ES">
    <seg>Para diagnóstico <ph x="1" type="13" />in vitro<ph x="2" type="14" />.</seg>
  </tuv>

<!--(Corresponding <tuv xml:lang="de-DE"> node to be inserted here, matched by attribute value of element "prop", attribue "type")-->

</tu>
</root>

示例文件 2:

<body>
<tu creationdate="20130704T142816Z" changedate="20130704T142816Z" lastusagedate="20130704T142837Z" usagecount="1">
  <prop type="x-Context">0, 0</prop>
  <prop type="x-Context">106215398363146103, 106215398363146103</prop>
  <prop type="x-Origin">TM</prop>
  <prop type="x-ConfirmationLevel">Translated</prop>
 <tuv xml:lang="de-DE">
    <seg>FFPET RNA Isolation Kit2</seg>
  </tuv>
</tu>
<tu creationdate="20130704T142816Z" changedate="20130704T142816Z" lastusagedate="20130704T142837Z" usagecount="1">
  <prop type="x-Context">-2654973059922618556, -2654973059922618556</prop>
  <prop type="x-Origin">TM</prop>
  <prop type="x-ConfirmationLevel">Translated</prop>
  <tuv xml:lang="de-DE">
    <seg><ph x="1" type="13" />In-vitro-<ph x="2" type="14" />Diagnostikum.</seg>
  </tuv>
</tu>
4

1 回答 1

0

请尝试以下 XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">

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

<xsl:variable name="lookup" select="document('test.xml')"/>

    <xsl:template match="tu">
        <!-- store the left value, before comma and space -->
        <xsl:variable name="propID">
            <xsl:value-of select="tokenize(./prop[@type='x-Context'], ', ')[1]"/>
        </xsl:variable>
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates/>
            <!-- loop through the lookup XML -->
            <xsl:for-each select="$lookup/body/tu/prop[@type='x-Context']">
                <!-- store the left value, before comma and space from the lookup -->
                <xsl:variable name="lookup_propID" select="tokenize(., ', ')[1]"/>
                <!-- compare the two variables, 
                    is it possible that the value can be '0'?
                    If it is, replace $propID[.!='0'] to $propID-->
                <xsl:choose>
                    <xsl:when test="$propID[.!='0']=$lookup_propID">
                        <!-- apply the target matched node -->
                        <xsl:apply-templates select="following-sibling::tuv[@xml:lang='de-DE']"/>
                    </xsl:when>
                </xsl:choose>
            </xsl:for-each>

        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>
于 2014-02-10T06:01:12.413 回答