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在toc.ncx中添加播放顺序?_Xslt - Fatal编程技术网

如何使用XSLT在toc.ncx中添加播放顺序?

如何使用XSLT在toc.ncx中添加播放顺序?,xslt,Xslt,如果我决定在navmap中现有toc.ncx的开头添加toc.ncx中的navpoint元素,则除了手动之外,没有办法对playOrder编号进行重新排序。如果有许多navpoint元素,那么这可能会非常乏味 输入 为医疗保健作出选择 掩护 半头衔 假设输出如下: <navPoint id="nav-1" playOrder="1"> <navLabel> <text>1</text> </navL

如果我决定在navmap中现有toc.ncx的开头添加toc.ncx中的navpoint元素,则除了手动之外,没有办法对playOrder编号进行重新排序。如果有许多navpoint元素,那么这可能会非常乏味

输入


为医疗保健作出选择
掩护
半头衔
假设输出如下:

<navPoint id="nav-1" playOrder="1">
      <navLabel>
        <text>1</text>
      </navLabel>
      <content src="Text/Section0002.xhtml"/>
    </navPoint>
    <navPoint id="nav-2" playOrder="2">
      <navLabel>
        <text>2</text>
      </navLabel>
      <content src="Text/Section0003.xhtml"/>
    </navPoint>

1.
2.
XSLT代码:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <!-- Recursive copy template -->    
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>
<xsl:template match="navPoint">
  <xsl:copy>
    <xsl:attribute name="playOrder">1</xsl:attribute>
    <xsl:apply-templates />
  </xsl:copy>
</xsl:template>
    <xsl:template match="@playOrder">
        <xsl:attribute name="playOrder"><xsl:number count="*[@playOrder]" level="any"/></xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

1.
此代码不起作用,您能告诉我正确的代码吗使用此代码:

<xsl:attribute name="playOrder"><xsl:number count="navPoint" level="any"/>/xsl:attribute>
/xsl:attribute>
而不是

<xsl:attribute name="playOrder">1</xsl:attribute>
1
并删除模板

   <xsl:template match="@playOrder">
    <xsl:attribute name="playOrder"><xsl:number count="*[@playOrder]" level="any"/></xsl:attribute>
</xsl:template>


请参见

处的变换假设您只需要正常的1,2,3编号,您可以
count()
前面的节点

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

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

    <xsl:template match="navPoint">
      <xsl:copy>
        <xsl:attribute name="playOrder">
          <xsl:value-of select="count(preceding-sibling::navPoint) + 1" />
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:copy>
    </xsl:template>

</xsl:stylesheet>


未特别添加属性element@Lucky,请参见“对不起,打扰了”。我正在更新输入字段中的完整代码。。在这种情况下,如果您错过了xslt中的名称空间,那么它将不起作用。请参阅now@Lucky,为此,您还添加了id属性,请参阅我希望在元素(navPoint)中添加特定属性(播放顺序)。。。我正试图修改这段代码,但没有用。。我这边有什么问题吗。。。如果你不介意的话,需要进行深入的解释。这就是为什么你总是需要在你的问题中添加预期的结果。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

    <xsl:template match="navPoint">
      <xsl:copy>
        <xsl:attribute name="playOrder">
          <xsl:value-of select="count(preceding-sibling::navPoint) + 1" />
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:copy>
    </xsl:template>

</xsl:stylesheet>