转到XSL中带有特殊属性的标记

时间:2014-07-17 09:51:55

标签: html xml xslt

我想转到一个特殊的父标签,该标签具有特殊属性 XML:

<Rang type="header">
       <Cellule>
            <Paragraphe>Modifications</Paragraphe>
       </Cellule>
       <Cellule>
            <Paragraphe>You need to use</Paragraphe>
        </Cellule>
</Rang>
<Rang type="normal">
        <Cellule>
            <Paragraphe>Buil</Paragraphe>
        </Cellule>
        <Cellule>
            <Paragraphe>
                n°6650 cerfa n°10867*04
            </Paragraphe>
        </Cellule>
</Rang>

如果type等于header,我想进入获取值。如果类型等于normal,我想要相同。

1 个答案:

答案 0 :(得分:0)

您需要什么输出并不是很清楚。但是这个XSLT确实有两个Rang元素的模板:

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

    <xsl:template match="/">
        <html>
            <xsl:apply-templates select="*"/>
        </html>
    </xsl:template>

    <xsl:template match="Rang[@type='header']">
        <h1>
            <xsl:value-of select="Cellule/Paragraphe"/>
        </h1>
    </xsl:template>

    <xsl:template match="Rang[@type='normal']">
        <xsl:value-of select="'some value'"/>
    </xsl:template>
</xsl:stylesheet>

您可以使用以下模板选择headernormal

<xsl:template match="Rang[@type='header']| Rang[@type='normal']">
        <!-- select you values -->
</xsl:template>
相关问题