0

我有一个变量 varLocationRegion 并且我已经存储了整个 xml(其中包含两个元素位置和区域。现在我想通过匹配位置在 xslt 中循环该变量以获取区域的值。请告知。谢谢!

<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data xmlns:wd="urn:com.workday/bsvc">
    <wd:Report_Entry>
        <wd:Location_ID>111</wd:Location_ID>
        <wd:Region_Ref_ID>UNITED_STATES_REGION</wd:Region_Ref_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Location_ID>111V</wd:Location_ID>
    </wd:Report_Entry>
</wd:Report_Data>
4

1 回答 1

0

根据您提供的信息,您可以尝试以下方法: XSLT 1.0 的解决方案可以通过以下方式尝试:使用 Muenchian Grouping 将 xml 中的唯一 Location_ID 组合在一起,并使用已经可用的唯一 Location_ID 迭代原始 xml查找与特定 Location_ID 关联的 Region_Ref_ID 的列表。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:wd="urn:com.workday/bsvc">
  <xsl:output method="text"/>
  <xsl:key name="uniqueLocation" match="wd:Report_Entry" use="wd:Location_ID"/>
  <xsl:template match="/">
    <!--variable called data is the variable that contains your xml-->
    <xsl:variable name="uniqueLocationData" select="$data/wd:Report_Data/wd:Report_Entry[count(.|key('uniqueLocation',wd:Location_ID)[1])=1]"/>
    <xsl:for-each select="$data/wd:Report_Data/wd:Report_Entry/wd:Region_Ref_ID[$data/wd:Report_Data/wd:Report_Entry/wd:Location_ID=$uniqueLocationData/wd:Location_ID]">
      <xsl:value-of select="."/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
于 2015-01-31T05:45:09.373 回答