Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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
Templates XSL1.0中模板结果的滚动和_Templates_Xslt_Call_Xslt 1.0 - Fatal编程技术网

Templates XSL1.0中模板结果的滚动和

Templates XSL1.0中模板结果的滚动和,templates,xslt,call,xslt-1.0,Templates,Xslt,Call,Xslt 1.0,我已经广泛地搜索了这个例子,但到目前为止还没有成功地应用sum模板使我的XSTL工作 这是每个平面要素上不同的XML行数 <PlanFeatures> <PlanFeature name="Line0001"> <CoordGeom> <Line> <Start pntRef="7540">5605 8950 1020</Start> <End pntRef="7541">5605

我已经广泛地搜索了这个例子,但到目前为止还没有成功地应用sum模板使我的XSTL工作

这是每个平面要素上不同的XML行数

<PlanFeatures> 
 <PlanFeature name="Line0001">
  <CoordGeom>
   <Line>
    <Start pntRef="7540">5605 8950 1020</Start>
    <End pntRef="7541">5605 8951 1019</End>
   </Line>
   <Line>
    <Start pntRef="7541">5605 8951 1019</Start>
    <End pntRef="7542">5605 8947 1019</End>
   </Line>
   <Line>
    <Start pntRef="7542">5605 8947 1019</Start>
    <End pntRef="7543">5605 8940 1011</End>
   </Line>
   <Line>
    <Start pntRef="7543">5605 8940 1011</Start>
    <End pntRef="7544">5605 8931 1020</End>
   </Line>  
  </CoordGeom>
 </PlanFeature>
</PlanFeatures> 
但是我想

Line0001::7540-7541: 1.414, 7541-7542: 2.000, 7542-7543: 12.042, 7543-7544: 12.728 -- 28.184
任何帮助都将不胜感激。。。这个网站上的例子已经帮了我很大的忙,但我似乎无法克服这个障碍

干杯


Chris

您可以通过一些相对简单的递归和参数传递来实现这一点。尝试用以下四个模板替换第一个模板:

  <xsl:template match="/">
    <xsl:for-each select="$XML">
      <xsl:apply-templates 
           select="landxml:LandXML/landxml:PlanFeatures/landxml:PlanFeature" />
    </xsl:for-each>
  </xsl:template>

  <xsl:template match ="landxml:PlanFeature">
    <xsl:value-of select="concat(@name, '::')" />
    <xsl:apply-templates select="landxml:CoordGeom/landxml:Line[1]" />
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="landxml:Line">
    <xsl:param name="total" select="0" />

    <xsl:value-of 
         select="concat(landxml:Start/@pntRef, '-', landxml:End/@pntRef, ': ')"/>

    <xsl:variable name="len">
      <xsl:call-template name="root">
        <xsl:with-param name="X">
          <xsl:call-template name="seg" />
        </xsl:with-param>
      </xsl:call-template>
    </xsl:variable>
    <xsl:value-of select="$len"/>

    <xsl:variable name="next" select="following-sibling::landxml:Line[1]" />
    <xsl:variable name="newTot" select="$total + $len" />
    <xsl:choose>
      <xsl:when test="$next">
        <xsl:text>, </xsl:text>
        <xsl:apply-templates select="$next">
          <xsl:with-param name="total" select="$newTot" />
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="concat(' -- ', format-number($newTot, '#.000'))" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="seg">
    <xsl:variable name="lista" select="landxml:Start"/>
    <xsl:variable name="x1" select="substring-before($lista,' ')"/>
    <xsl:variable name="yt1" select="substring-after($lista,' ')"/>
    <xsl:variable name="y1" select="substring-before($yt1,' ')"/>
    <xsl:variable name="z1" select="substring-after($yt1,' ')"/>
    <xsl:variable name="listb" select="landxml:End"/>
    <xsl:variable name="x2" select="substring-before($listb,' ')"/>
    <xsl:variable name="yt2" select="substring-after($listb,' ')"/>
    <xsl:variable name="y2" select="substring-before($yt2,' ')"/>
    <xsl:variable name="z2" select="substring-after($yt2,' ')"/>

    <xsl:value-of select= "($x2 - $x1)*($x2 - $x1)+
                           ($y2 - $y1)*($y2 - $y1)+
                           ($z2 - $z1)*($z2 - $z1)"/>
  </xsl:template>

您可能需要预先解释特定输入的预期结果。就目前情况而言,人们只是略过这一点,然后继续前进,因为不清楚你想要什么。谢谢你的建议。我希望现在更清楚一点。您的示例输出中的数字似乎与输入中的值不匹配,您的示例总和似乎不匹配,但我是否正确地假设这些值不应该完全匹配?嗨,JL,是的,这是我的一个错误。。。很抱歉,谢谢你纠正它。为了简单起见,我构建了坐标值,结果把它搞砸了。我现在正在浏览你的解决方案,我认为这对我来说是有意义的。非常感谢,克里斯,这太棒了。做我需要的,它的方式说明了我之前的错误。谢谢你帮助一个新手,非常感谢!克里斯
Line0001::7540-7541: 1.414, 7541-7542: 2.000, 7542-7543: 12.042, 7543-7544: 12.728 -- 28.184
  <xsl:template match="/">
    <xsl:for-each select="$XML">
      <xsl:apply-templates 
           select="landxml:LandXML/landxml:PlanFeatures/landxml:PlanFeature" />
    </xsl:for-each>
  </xsl:template>

  <xsl:template match ="landxml:PlanFeature">
    <xsl:value-of select="concat(@name, '::')" />
    <xsl:apply-templates select="landxml:CoordGeom/landxml:Line[1]" />
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="landxml:Line">
    <xsl:param name="total" select="0" />

    <xsl:value-of 
         select="concat(landxml:Start/@pntRef, '-', landxml:End/@pntRef, ': ')"/>

    <xsl:variable name="len">
      <xsl:call-template name="root">
        <xsl:with-param name="X">
          <xsl:call-template name="seg" />
        </xsl:with-param>
      </xsl:call-template>
    </xsl:variable>
    <xsl:value-of select="$len"/>

    <xsl:variable name="next" select="following-sibling::landxml:Line[1]" />
    <xsl:variable name="newTot" select="$total + $len" />
    <xsl:choose>
      <xsl:when test="$next">
        <xsl:text>, </xsl:text>
        <xsl:apply-templates select="$next">
          <xsl:with-param name="total" select="$newTot" />
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="concat(' -- ', format-number($newTot, '#.000'))" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="seg">
    <xsl:variable name="lista" select="landxml:Start"/>
    <xsl:variable name="x1" select="substring-before($lista,' ')"/>
    <xsl:variable name="yt1" select="substring-after($lista,' ')"/>
    <xsl:variable name="y1" select="substring-before($yt1,' ')"/>
    <xsl:variable name="z1" select="substring-after($yt1,' ')"/>
    <xsl:variable name="listb" select="landxml:End"/>
    <xsl:variable name="x2" select="substring-before($listb,' ')"/>
    <xsl:variable name="yt2" select="substring-after($listb,' ')"/>
    <xsl:variable name="y2" select="substring-before($yt2,' ')"/>
    <xsl:variable name="z2" select="substring-after($yt2,' ')"/>

    <xsl:value-of select= "($x2 - $x1)*($x2 - $x1)+
                           ($y2 - $y1)*($y2 - $y1)+
                           ($z2 - $z1)*($z2 - $z1)"/>
  </xsl:template>
Line0001::7540-7541: 1.414, 7541-7542: 4.000, 7542-7543: 10.630, 7543-7544: 12.728 -- 28.772