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
Xml 对来自两个不同父级的项目进行分组/分页_Xml_Xslt - Fatal编程技术网

Xml 对来自两个不同父级的项目进行分组/分页

Xml 对来自两个不同父级的项目进行分组/分页,xml,xslt,Xml,Xslt,我是XSLT的新手,从90年代末开始就没有接触过它,但最近我开始了一个涉及XSLT的个人项目 我有以下XML,我正试图从中构建HTML字符表: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="./Statblock.xslt"?> <Character> <Name value="Seiyatomo"/> <Family value

我是XSLT的新手,从90年代末开始就没有接触过它,但最近我开始了一个涉及XSLT的个人项目

我有以下XML,我正试图从中构建HTML字符表:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="./Statblock.xslt"?>
<Character>
 <Name value="Seiyatomo"/>
 <Family value="Soshi"/>
 <Clan value="Scorpion"/>
 <School value="Soshi Illusionist School"/>
 <Titles/>
 <Ninjo value=""/>
 <Giri value=""/>
 <Abilities>
  <Ability description="" name="The Kami's Whisper" />
 </Abilities>
 <Skills>
  ...
 </Skills>
 <Rings>
  ...
 </Rings>
 <Social glory="50" honor="35" status="35"/>
 <Wealth bu="0" koku="6" zeni="0"/>
 <Derived composure="8" endurance="4" focus="4" vigilance="3"/>
 <RankStatus titlestatus="Title: , Title XP: 0" curricstatus="Rank: 1, XP in Rank: 0"/>
 <Curriculum>
    ...
 </Curriculum>
 <Title/>
 <Techniques>
  <Technique name="Bō of Water" />
  <Technique name="Cloak of Night" />
  <Technique name="Token of Memory" />
  <Technique name="Commune with the Spirits" />
  <Technique name="All in Jest" />
  <Technique name="Dangerous Allure" />
  <Technique name="Shadowlands Taint (Water)" />
  <Technique name="Curiosity" />
  <Technique name="Dark Secret" />
  <Technique name="Fallen Ancestor" />
 </Techniques>
 <PersonalTraits/>
 <Equipment>
    ...
 </Equipment>
 <Heritage value="Glorious Sacrifice"/>
 <Notes value="..."/>
 <Advances/>
 <TotalXP value="0"/>
 <XPSpent value="0"/>
 <Portrait base64image=""/>
</Character>

...
...
...
...
我试图将能力和技术节点的组合列表分成9组,这样我将得到类似以下内容的输出:

<page>
  <ability>The Kami's Whisper</ability>
  <technique>Bō of Water</technique>
  <technique>Cloak of Night</technique>
  <technique>Token of Memory</technique>
  <technique>Commune with the Spirits</technique>
  <technique>All in Jest</technique>
  <technique>Dangerous Allure</technique>
  <technique>Shadowlands Taint (Water)</technique>
  <technique>Curiosity</technique>
</page>
<page>
  <technique>Dark Secret</technique>
  <technique>Fallen Ancestor</technique>
</page>

卡米的低语
Bō水
夜幕
记忆标记
与鬼魂交流
开玩笑
危险诱惑
阴影地带污染(水)
好奇心
秘密
堕落的祖先
XML中的和节点的数量是任意的,但我更希望所有节点在输出中都排在第一位,然后是节点

奖励积分,如果最后一个可以充满空条目,将页面填充到完整的9组,但这是第二个问题

我试图寻找类似的问题,但要么我没有看到任何类似的问题,要么我没有充分理解这些问题/答案,无法识别它们是重复的


注意:如果需要,可以让生成XML的应用程序的作者对XML进行一些更改,但我不能直接控制XML本身。

至少第一部分看起来很简单:

XSLT1.0

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/Character">
    <xsl:copy>
        <xsl:copy-of select="Name" />  
        <xsl:call-template name="paginate">
            <xsl:with-param name="nodes" select="Abilities/Ability | Techniques/Technique"/>
        </xsl:call-template>    
    </xsl:copy>
</xsl:template>

<xsl:template match="Ability">
    <ability>
        <xsl:value-of select="@name"/>
    </ability>
</xsl:template>

<xsl:template match="Technique">
    <technique>
        <xsl:value-of select="@name"/>
    </technique>
</xsl:template>

<xsl:template name="paginate">
    <xsl:param name="nodes"/>
    <xsl:param name="pagesize" select="9"/>
    <page>
        <xsl:apply-templates select="$nodes[position() &lt;= $pagesize]"/>
    </page>
    <xsl:if test="count($nodes) > $pagesize">
        <xsl:call-template name="paginate">
            <xsl:with-param name="nodes" select="$nodes[position() > $pagesize]"/>
        </xsl:call-template>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>


请说明您的处理器支持哪个版本的XSLT。有几个版本的XSLT?是的。正如我在问题中所说的,我上一次使用XSLT做任何有意义的事情是在90年代末。到目前为止,我发现的XSLT教程中没有一个提到不同的版本。在任何情况下,如果你想继续“奖励积分”,你需要回答我的问题。如果您不知道,请看这里如何找到答案:我向应用程序的作者提出了一个关于其库支持的XSLT版本的问题。当我得到回复时,我会更新另一条评论。太棒了。谢谢
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/Character">
    <xsl:copy>
        <xsl:copy-of select="Name" /> 
        <xsl:for-each-group select="Abilities/Ability | Techniques/Technique" group-by="(position()-1) idiv 9">
            <page>
                <xsl:apply-templates select="current-group()"/>
            </page>
        </xsl:for-each-group>
    </xsl:copy>
</xsl:template>

<xsl:template match="Ability | Technique">
    <xsl:element name="{lower-case(name())}">
        <xsl:value-of select="@name"/>
    </xsl:element>      
</xsl:template>

</xsl:stylesheet>
<xsl:for-each select="1 to 9 - count(current-group())">
    <technique/>
</xsl:for-each>