Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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 XSLT和属性中的数字_Templates_Xslt_Attributes_Numbers - Fatal编程技术网

Templates XSLT和属性中的数字

Templates XSLT和属性中的数字,templates,xslt,attributes,numbers,Templates,Xslt,Attributes,Numbers,我有这样一个xml片段: <p rend="noIndent">eget <seg type="comStart" n="com123"/>kunde<seg type="comEnd" n="com123"/> der i Anledning af disse <seg type="comStart" n="com13"/>kunde<seg type="comEnd" n="com13"/> Smaadigte være at s&

我有这样一个xml片段:

<p rend="noIndent">eget <seg type="comStart" n="com123"/>kunde<seg type="comEnd" n="com123"/> der i Anledning af disse <seg type="comStart" n="com13"/>kunde<seg type="comEnd" n="com13"/> Smaadigte være at s</p>

在s

我想更改n属性中的数字,使数字以1开头。对于类型属性中的每对comStat和comEnd,n-attribute中的值应相同,结果如下:

<p rend="noIndent">eget <seg type="comStart" n="com1"/>havde<seg type="comEnd" n="com1"/> der i Anledning af disse <seg type="comStart" n="com2"/>kunde<seg type="comEnd" n="com2"/> Smaadigte være at s</p>

在s

如何匹配xslt中相应的n属性


KSR

如果始终存在对,您可以使用
xsl:number
comStart
元素创建数字:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="3.0">

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:template match="*[@type = ('comStart', 'comEnd')]/@n">
      <xsl:attribute name="{name()}">n<xsl:number level="any" count="*[@type = 'comStart']"/></xsl:attribute>
  </xsl:template>

</xsl:stylesheet>

N

分别

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

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

  <xsl:template match="*[@type = 'comStart' or @type = 'comEnd']/@n">
      <xsl:attribute name="{name()}">n<xsl:number level="any" count="*[@type = 'comStart']"/></xsl:attribute>
  </xsl:template>

</xsl:stylesheet>

N

对于XSLT 1()。

如果始终存在对,则可以使用
xsl:number
comStart
元素创建数字:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="3.0">

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:template match="*[@type = ('comStart', 'comEnd')]/@n">
      <xsl:attribute name="{name()}">n<xsl:number level="any" count="*[@type = 'comStart']"/></xsl:attribute>
  </xsl:template>

</xsl:stylesheet>

N

分别

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

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

  <xsl:template match="*[@type = 'comStart' or @type = 'comEnd']/@n">
      <xsl:attribute name="{name()}">n<xsl:number level="any" count="*[@type = 'comStart']"/></xsl:attribute>
  </xsl:template>

</xsl:stylesheet>

N
对于XSLT1()