【问题标题】:I have a variable varLocationRegion and i have stored whole xml. Now i want to loop through that variable in xslt我有一个变量 varLocationRegion 并且我已经存储了整个 xml。现在我想遍历 xslt 中的那个变量
【发布时间】:2015-03-28 00:56:46
【问题描述】:

我有一个变量 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>

【问题讨论】:

  • indent code by four spaces 显示美化、整洁的 XML(我已经为您完成了)。此外,将您的 XSLT 样式表连同您期望的输出一起添加到问题中。
  • 你能发布你期望的输出吗???

标签: loops variables xslt pass-through


【解决方案1】:

根据您提供的信息,您可以尝试以下方法: 可以通过以下方式尝试 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>

【讨论】:

    猜你喜欢
    • 2018-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    相关资源
    最近更新 更多