Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
XSLT将每个重复节点转换为平面_Xslt_Biztalk - Fatal编程技术网

XSLT将每个重复节点转换为平面

XSLT将每个重复节点转换为平面,xslt,biztalk,Xslt,Biztalk,我有一个XML模式,需要从中提取值,但运气不太好 资源模式是: <Reading> <State> <StateValues> <Name> <Value> </StateValues> </State> <Reading> 在XSLT中,foreach和if通常是错误的方法。将模板应用于模式要有效得多。在这种情况下,您可以使用

我有一个XML模式,需要从中提取值,但运气不太好

资源模式是:

<Reading>
   <State>
      <StateValues>
         <Name>
         <Value>
      </StateValues>
   </State>
<Reading>

在XSLT中,
foreach
if
通常是错误的方法。将模板应用于模式要有效得多。在这种情况下,您可以使用两种方法:第一种方法设置根元素,并匹配要使用的元素:

<xsl:template match='/'>
  <Readings>
    <xsl:apply-templates select='Reading/State/StateValues'/>
  </Readings>
</xsl:template>

您试图使用的XSLT是什么?您误解了规范的某些内容。如果您向我们展示了您的代码,我们可以告诉您哪里出了问题,这比简单地为您提供解决方案要有用得多。我对您的问题投了否决票。如果您尝试了一些东西但失败了,您应该告诉我们您尝试了什么,以及它是如何失败的。很抱歉没有发布XSLT。希望我的编辑能回答任何问题。我试图在BizTalk中的脚本functoid中使用它。+1{Name}-我需要将根匹配更改为感谢您的回答。我曾经了解到更多关于这方面的知识,并使其发挥作用。非常感谢你的帮助。
<Readings>
  <Reading1>1234</Reading1>
  <Reading2>2345</Reading2>
  <Reading3>4321</Reading3>
</Readings>
<xsl:element name="ns0:Readings">
   <xsl:element name="ns0:Current">
         <xsl:for-each select="/*[local-name()='gatewayInterface' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Reading' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='State' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='StateValues' and namespace-uri()='http://biztalk.gateway.com']">               
            <xsl:choose>
               <xsl:when test="Name='TOTAL'">
            <xsl:element name="ns0:Total">
                <xsl:value-of select="/*[local-name()='gatewayInterface' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Reading' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='State' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='StateValues' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Name' and namespace-uri()='http://biztalk.gateway.com']/text()='Total'" />
            </xsl:element>
           </xsl:when>
        </xsl:choose>
        <xsl:choose>
           <xsl:when test="/*[local-name()='gatewayInterface' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Reading' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='State' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='StateValues' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Name' and namespace-uri()='http://biztalk.gateway.com']/text()='Reading1'">
        <xsl:element name="ns0:Reading1">
            <xsl:value-of select="/*[local-name()='gatewayInterface' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Reading' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='State' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='StateValues' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Name' and namespace-uri()='http://biztalk.gateway.com']/text()" />
            </xsl:element>
           </xsl:when>
        </xsl:choose>
        <xsl:choose>
           <xsl:when test="/*[local-name()='gatewayInterface' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Reading' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='State' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='StateValues' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Name' and namespace-uri()='http://biztalk.gateway.com']/text() = 'Reading2'">
        <xsl:element name="ns0:Reading2">
            <xsl:value-of select="/*[local-name()='gatewayInterface' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Reading' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='State' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='StateValues' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Name' and namespace-uri()='http://biztalk.gateway.com']/text()" />
            </xsl:element>
           </xsl:when>
        </xsl:choose>
        <xsl:choose>
           <xsl:when test="/*[local-name()='gatewayInterface' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Reading' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='State' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='StateValues' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Name' and namespace-uri()='http://biztalk.gateway.com']/text() = 'Reading3'">
        <xsl:element name="ns0:Reading3">
            <xsl:value-of select="/*[local-name()='gatewayInterface' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Reading' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='State' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='StateValues' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Name' and namespace-uri()='http://biztalk.gateway.com']/text()" />
            </xsl:element>
           </xsl:when>
        </xsl:choose>
        <xsl:choose>
           <xsl:when test="/*[local-name()='gatewayInterface' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Reading' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='State' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='StateValues' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Name' and namespace-uri()='http://biztalk.gateway.com']/text() = 'Reading4'">
        <xsl:element name="ns0:Reading4">
            <xsl:value-of select="/*[local-name()='gatewayInterface' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Reading' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='State' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='StateValues' and namespace-uri()='http://biztalk.gateway.com']/*[local-name()='Name' and namespace-uri()='http://biztalk.gateway.com']/text()" />
            </xsl:element>
           </xsl:when>
        </xsl:choose>
     </xsl:for-each>
   </xsl:element>
</xsl:element>
<xsl:template match='/'>
  <Readings>
    <xsl:apply-templates select='Reading/State/StateValues'/>
  </Readings>
</xsl:template>
<xsl:template match='StateValues'>
  <xsl:element name='{Name}'>
    <xsl:value-of select='Value' />
  </xsl:element>
</xsl:template>