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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/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
具有相同结构和多个级别的两个不同XML文件的xslt_Xslt_Xslt 1.0_Xslt 2.0 - Fatal编程技术网

具有相同结构和多个级别的两个不同XML文件的xslt

具有相同结构和多个级别的两个不同XML文件的xslt,xslt,xslt-1.0,xslt-2.0,Xslt,Xslt 1.0,Xslt 2.0,我有两个法语和英语的xml文件来生成HTML。我正在使用xslt document()函数访问英语XML的内容。我的第二级/ XML1法语 <?xml version="1.0" encoding="UTF-8"?> <Root> <group-container> <group-name>Comptes</group-name> <group-tit

我有两个法语和英语的xml文件来生成HTML。我正在使用xslt document()函数访问英语XML的内容。我的第二级
/

XML1法语

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <group-container>
        <group-name>Comptes</group-name>
        <group-title>
            <title-name>Consulter des comptes</title-name>                  
        </group-title>
        <group-title>
            <title-name>Comptes</title-name>                   
        </group-title>
    </group-container>
    <group-container>
        <group-name>Paiements</group-name>
        <group-title>
            <title-name>Historique</title-name>
        </group-title>
        <group-title>
            <title-name>Nouveau compte</title-name>
        </group-title>
    </group-container>
    <group-container>
        <group-name>Cartes</group-name>
        <group-title>
            <title-name>Créer un virement</title-name>
        </group-title>
        <group-title>
            <title-name>Virements</title-name>
        </group-title>
    </group-container>  
</Root>

Comptes
康普茨领事
Comptes
付款
历史的
新公司
卡特斯
Créer-un-virement
病毒
XML2英语

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <group-container>
        <group-name>Accounts</group-name>
        <group-title>
            <title-name>open new account</title-name>                  
        </group-title>
        <group-title>
            <title-name> linked accounts</title-name>                   
        </group-title>
    </group-container>
    <group-container>
        <group-name>Payments</group-name>
        <group-title>
            <title-name>History</title-name>
        </group-title>
        <group-title>
            <title-name>New Payment</title-name>
        </group-title>
    </group-container>
        <group-container>
        <group-name>cards</group-name>
        <group-title>
            <title-name>Make a Payment</title-name>
        </group-title>
        <group-title>
            <title-name>statement</title-name>
        </group-title>
    </group-container>  
</Root>

账户
开立新帐户
联系账户
付款
历史
新付款
卡
付款
陈述
XSLT


预期产量

<div class="first-level-inner">
    <div>
        <span data-webanalytics="menunavigation.Accounts">
            <span>Comptes</span>
        </span>
    </div>
    <div>
        <span data-webanalytics="menunavigation.Payments">
            <span>Paiements</span>
        </span>
    </div>
    <div>
        <span data-webanalytics="menunavigation.Cards">
            <span>Cartes</span>
        </span>
    </div>
</div>
<div class="second-level-inner">
    <h5>Consulter des comptes</h5>
    <span data-webanalytics="menunavigation.open new account"/>
    <h5>Comptes</h5>
    <span data-webanalytics="menunavigation.linked accounts"/>
</div>
<div class="second-level-inner">
    <h5>Historique</h5>
    <span data-webanalytics="menunavigation.History"/>
    <h5>Nouveau compte</h5>
    <span data-webanalytics="menunavigation.New Payment"/>
</div>
<div class="second-level-inner">
    <h5>Créer un virement</h5>
    <span data-webanalytics="menunavigation.Make a Payment"/>
    <h5>Virements</h5>
    <span data-webanalytics="menunavigation.statement"/>
</div>

Comptes
付款
卡特斯
康普茨领事
Comptes
历史的
新公司
Créer-un-virement
病毒

我可以通过
position()
成功地获得第一级。但是,我对第二级位置感到迷茫。

您需要将外部位置作为参数传递,例如

<xsl:template match="group-container" mode="second-level">
    <xsl:variable name="pos" select="position()"/>
    <div class="second-level-inner">
        <xsl:apply-templates select="group-title" mode="title">
           <xsl:with-param name="pos" select="$pos" tunnel="yes"/>
         </xsl:apply-templates>
    </div>
</xsl:template>

加上



除了传递外部位置,您还可以选择传递
文档($en xml analytics)/Root/group容器[$pos]
,并使用它。

您需要将外部位置作为参数传递,例如

<xsl:template match="group-container" mode="second-level">
    <xsl:variable name="pos" select="position()"/>
    <div class="second-level-inner">
        <xsl:apply-templates select="group-title" mode="title">
           <xsl:with-param name="pos" select="$pos" tunnel="yes"/>
         </xsl:apply-templates>
    </div>
</xsl:template>

加上



您也可以选择传递
文档($en xml analytics)/Root/group容器[$pos]
并使用它,而不是传递外部位置。

为什么不简单地执行以下操作:

<xsl:template match="/Root">
    <xsl:variable name="en-root" select="document($path-to-en-xml)/Root" />
    <!-- first-level -->
    <div class="first-level-inner">
        <xsl:for-each select="group-container">
            <xsl:variable name="i" select="position()" />
            <div>
                <span data-webanalytics="menunavigation.{$en-root/group-container[$i]/group-name}">
                    <span>
                        <xsl:value-of select="group-name"/>
                    </span>
                </span>
            </div>
        </xsl:for-each>
    </div>
    <!-- second-level -->
    <div class="second-level-inner">
        <xsl:for-each select="group-container/group-title">
            <xsl:variable name="j" select="position()" />
            <h5>
                <xsl:value-of select="title-name"/>
            </h5>
            <span data-webanalytics="menunavigation.{($en-root/group-container/group-title)[$j]/title-name}"/>
        </xsl:for-each>
    </div>
</xsl:template>


请注意,结果是一个XML片段,没有单个根元素。

为什么不简单地执行以下操作:

<xsl:template match="/Root">
    <xsl:variable name="en-root" select="document($path-to-en-xml)/Root" />
    <!-- first-level -->
    <div class="first-level-inner">
        <xsl:for-each select="group-container">
            <xsl:variable name="i" select="position()" />
            <div>
                <span data-webanalytics="menunavigation.{$en-root/group-container[$i]/group-name}">
                    <span>
                        <xsl:value-of select="group-name"/>
                    </span>
                </span>
            </div>
        </xsl:for-each>
    </div>
    <!-- second-level -->
    <div class="second-level-inner">
        <xsl:for-each select="group-container/group-title">
            <xsl:variable name="j" select="position()" />
            <h5>
                <xsl:value-of select="title-name"/>
            </h5>
            <span data-webanalytics="menunavigation.{($en-root/group-container/group-title)[$j]/title-name}"/>
        </xsl:for-each>
    </div>
</xsl:template>


请注意,结果是一个XML片段,没有单个根元素。

我尝试了这个方法,但得到了以下错误<代码>第32:75行的错误1:对于xsl:apply templates参数中的属性“tunnel”,唯一允许的值是第31:61行的“no”错误2:第32:75行的xsl:apply templates错误3:xsl:param必须立即位于模板中,函数或样式表,是否需要从
内部传递param?@user2628187,对不起,我在
xsl:apply templates
内部使用了错误的
xsl:param
来传递所需的参数,
xsl:with param
@user2628187,至于您在第二条评论中的问题,我不太确定它是否询问您是否需要传递参数或正在寻找替代方案,或者您是否想知道从哪个模板传递参数。我尝试了这个,但我得到以下错误<代码>第32:75行的错误1:对于xsl:apply templates参数中的属性“tunnel”,唯一允许的值是第31:61行的“no”错误2:第32:75行的xsl:apply templates错误3:xsl:param必须立即位于模板中,函数或样式表,是否需要从
内部传递param?@user2628187,对不起,我在
xsl:apply templates
内部使用了错误的
xsl:param
来传递所需的参数,
xsl:with param
@user2628187,至于您在第二条评论中的问题,我不太确定它是否询问您是否需要传递参数或正在寻找替代方案,或者您是否想知道从哪个模板传递参数。非常感谢@Martin Honnen的工作。我不是Martin Honnen。我仍然认为你让事情变得比需要的更复杂了。非常感谢@Martin Honnen的工作。我不是Martin Honnen。我仍然认为你让事情变得比需要的更复杂。