XSL 应用模板不起作用...可能是 XPath 错误

发布于 2024-08-29 15:03:19 字数 8495 浏览 4 评论 0原文

我已将 mny 样式表转换为使用应用模板而不是调用模板,并且它对于我的其他样式表(更复杂)工作得很好,但即使认为它是一个简单得多的模板,它似乎也不起作用。

它输出的只是性别节点和用户级节点。我认为这与我的 Xpath 有关。

我想要的只是输出 <用户>信息,没有别的

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

    <xsl:template name="hoo" match="/">
        <html>
            <head>
                <title>Registered Members</title>
                <link rel="stylesheet" type="text/css" href="user.css" />
            </head>
            <body>
                <h1>Registered Members</h1>
                <xsl:for-each select="folktask/member/user">

                    <div class="userdiv">

                        <xsl:apply-templates/>

                    </div>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="folktask/member/user">
        <xsl:apply-templates select="@id"/>
        <xsl:apply-templates select="personal/name"/>
        <xsl:apply-templates select="personal/address1"/>
        <xsl:apply-templates select="personal/city"/>
        <xsl:apply-templates select="personal/county"/>
        <xsl:apply-templates select="personal/postcode"/>
        <xsl:apply-templates select="personal/telephone"/>
        <xsl:apply-templates select="personal/mobile"/>
        <xsl:apply-templates select="personal/email"/>
        <xsl:apply-templates select="personal"/>
        <xsl:apply-templates select="account/username"/>
        <xsl:apply-templates select="account"/>
    </xsl:template>

    <xsl:template match="@id">
        <div class="heading bold"><h2>USER ID: <xsl:value-of select="." /></h2></div>
    </xsl:template>

    <xsl:template match="personal/name">
        <div class="small bold">NAME:</div> 
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/address1">
        <div class="small bold">ADDRESS:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/city">
        <div class="small bold">CITY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/county">
        <div class="small bold">COUNTY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/postcode">
        <div class="small bold">POSTCODE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/telephone">
        <div class="small bold">TELEPHONE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/mobile">
        <div class="small bold">MOBILE:</div>
        <div class="large"><xsl:value-of select="." />
        </div>
    </xsl:template>

    <xsl:template match="personal/email">
        <div class="small bold">EMAIL:</div>
        <div class="large">
            <xsl:element name="a">
                <xsl:attribute name="href">
                    <xsl:text>mailto:</xsl:text>
                    <xsl:value-of select="." />
                </xsl:attribute>
                <xsl:value-of select="." />
            </xsl:element>
        </div>
    </xsl:template>

    <xsl:template match="personal">
    <div class="small bold">SEX:</div>
    <div class="colored bold">
        <xsl:choose>
            <xsl:when test="sex='Male'">
                <div class="sex male"><xsl:value-of select="sex/."/></div>
            </xsl:when>
            <xsl:otherwise>
                <div class="sex female"><xsl:value-of select="sex/."/></div>
            </xsl:otherwise>
        </xsl:choose>
    </div>
    </xsl:template>

    <xsl:template match="account/username">
        <div class="small bold">USERNAME:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>


    <xsl:template match="account">
        <div class="small bold">ACCOUNT TYPE:</div>
        <div class="colored ">
        <xsl:choose>
            <xsl:when test="userlevel='1'">
                <div class="nml bold">Normal User</div>
            </xsl:when>

            <xsl:when test="userlevel='2'">
                <div class="vol bold">Volunteer</div>
            </xsl:when>

            <xsl:when test="userlevel='3'">
                <div class="org bold">Organiser</div>
            </xsl:when>

            <xsl:otherwise>
                <div class="name adm bold">Administrator</div>
            </xsl:otherwise>
        </xsl:choose>
        </div>
    </xsl:template>

</xsl:stylesheet> 

,还有我的一些 xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="users.xsl"?>
<folktask xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="folktask.xsd">
    <member>
        <user id="1">
            <personal>
                <name>Abbie Hunt</name>
                <sex>Female</sex>
                <address1>108 Access Road</address1>
                <address2></address2>
                <city>Wells</city>
                <county>Somerset</county>
                <postcode>BA5 8GH</postcode>
                <telephone>01528927616</telephone>
                <mobile>07085252492</mobile>
                <email>[email protected]</email>
            </personal>
            <account>
                <username>AdRock</username>
                <password>269eb625e2f0cf6fae9a29434c12a89f</password>
                <userlevel>4</userlevel>
                <signupdate>2010-03-26T09:23:50</signupdate>
            </account>
        </user>
        <volunteer id="1">
            <roles></roles>
            <region>South West</region>
        </volunteer>
    </member>
    <member>
        <user id="2">
            <personal>
                <name>Aidan Harris</name>
                <sex>Male</sex>
                <address1>103 Aiken Street</address1>
                <address2></address2>
                <city>Chichester</city>
                <county>Sussex</county>
                <postcode>PO19 4DS</postcode>
                <telephone>01905149894</telephone>
                <mobile>07784467941</mobile>
                <email>[email protected]</email>
            </personal>
            <account>
                <username>AmbientExpert</username>
                <password>8e64214160e9dd14ae2a6d9f700004a6</password>
                <userlevel>2</userlevel>
                <signupdate>2010-03-26T09:23:50</signupdate>
            </account>
        </user>
        <volunteer id="2">
            <roles>Van Driver,gas Fitter</roles>
            <region>South Central</region>
        </volunteer>
    </member>
</folktask>

I have converted mny stylesheet to use apply templates instead of call templates and it worked fine for my other styesheet, which was more complicated, but this one doesn't seem to work even thought it is a much simpler template.

All that it outputs is the sex node and the userlevel node. I think it has to do with my Xpath.

All i want is to output the < user > information, nothing else

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

    <xsl:template name="hoo" match="/">
        <html>
            <head>
                <title>Registered Members</title>
                <link rel="stylesheet" type="text/css" href="user.css" />
            </head>
            <body>
                <h1>Registered Members</h1>
                <xsl:for-each select="folktask/member/user">

                    <div class="userdiv">

                        <xsl:apply-templates/>

                    </div>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="folktask/member/user">
        <xsl:apply-templates select="@id"/>
        <xsl:apply-templates select="personal/name"/>
        <xsl:apply-templates select="personal/address1"/>
        <xsl:apply-templates select="personal/city"/>
        <xsl:apply-templates select="personal/county"/>
        <xsl:apply-templates select="personal/postcode"/>
        <xsl:apply-templates select="personal/telephone"/>
        <xsl:apply-templates select="personal/mobile"/>
        <xsl:apply-templates select="personal/email"/>
        <xsl:apply-templates select="personal"/>
        <xsl:apply-templates select="account/username"/>
        <xsl:apply-templates select="account"/>
    </xsl:template>

    <xsl:template match="@id">
        <div class="heading bold"><h2>USER ID: <xsl:value-of select="." /></h2></div>
    </xsl:template>

    <xsl:template match="personal/name">
        <div class="small bold">NAME:</div> 
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/address1">
        <div class="small bold">ADDRESS:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/city">
        <div class="small bold">CITY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/county">
        <div class="small bold">COUNTY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/postcode">
        <div class="small bold">POSTCODE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/telephone">
        <div class="small bold">TELEPHONE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/mobile">
        <div class="small bold">MOBILE:</div>
        <div class="large"><xsl:value-of select="." />
        </div>
    </xsl:template>

    <xsl:template match="personal/email">
        <div class="small bold">EMAIL:</div>
        <div class="large">
            <xsl:element name="a">
                <xsl:attribute name="href">
                    <xsl:text>mailto:</xsl:text>
                    <xsl:value-of select="." />
                </xsl:attribute>
                <xsl:value-of select="." />
            </xsl:element>
        </div>
    </xsl:template>

    <xsl:template match="personal">
    <div class="small bold">SEX:</div>
    <div class="colored bold">
        <xsl:choose>
            <xsl:when test="sex='Male'">
                <div class="sex male"><xsl:value-of select="sex/."/></div>
            </xsl:when>
            <xsl:otherwise>
                <div class="sex female"><xsl:value-of select="sex/."/></div>
            </xsl:otherwise>
        </xsl:choose>
    </div>
    </xsl:template>

    <xsl:template match="account/username">
        <div class="small bold">USERNAME:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>


    <xsl:template match="account">
        <div class="small bold">ACCOUNT TYPE:</div>
        <div class="colored ">
        <xsl:choose>
            <xsl:when test="userlevel='1'">
                <div class="nml bold">Normal User</div>
            </xsl:when>

            <xsl:when test="userlevel='2'">
                <div class="vol bold">Volunteer</div>
            </xsl:when>

            <xsl:when test="userlevel='3'">
                <div class="org bold">Organiser</div>
            </xsl:when>

            <xsl:otherwise>
                <div class="name adm bold">Administrator</div>
            </xsl:otherwise>
        </xsl:choose>
        </div>
    </xsl:template>

</xsl:stylesheet> 

and some of my xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="users.xsl"?>
<folktask xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="folktask.xsd">
    <member>
        <user id="1">
            <personal>
                <name>Abbie Hunt</name>
                <sex>Female</sex>
                <address1>108 Access Road</address1>
                <address2></address2>
                <city>Wells</city>
                <county>Somerset</county>
                <postcode>BA5 8GH</postcode>
                <telephone>01528927616</telephone>
                <mobile>07085252492</mobile>
                <email>[email protected]</email>
            </personal>
            <account>
                <username>AdRock</username>
                <password>269eb625e2f0cf6fae9a29434c12a89f</password>
                <userlevel>4</userlevel>
                <signupdate>2010-03-26T09:23:50</signupdate>
            </account>
        </user>
        <volunteer id="1">
            <roles></roles>
            <region>South West</region>
        </volunteer>
    </member>
    <member>
        <user id="2">
            <personal>
                <name>Aidan Harris</name>
                <sex>Male</sex>
                <address1>103 Aiken Street</address1>
                <address2></address2>
                <city>Chichester</city>
                <county>Sussex</county>
                <postcode>PO19 4DS</postcode>
                <telephone>01905149894</telephone>
                <mobile>07784467941</mobile>
                <email>[email protected]</email>
            </personal>
            <account>
                <username>AmbientExpert</username>
                <password>8e64214160e9dd14ae2a6d9f700004a6</password>
                <userlevel>2</userlevel>
                <signupdate>2010-03-26T09:23:50</signupdate>
            </account>
        </user>
        <volunteer id="2">
            <roles>Van Driver,gas Fitter</roles>
            <region>South Central</region>
        </volunteer>
    </member>
</folktask>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ま柒月 2024-09-05 15:03:19

问题出在这段代码中

   <xsl:for-each select="folktask/member/user">

        <div class="userdiv">

            <xsl:apply-templates/>

        </div>
    </xsl:for-each>

这会将模板应用于当前 user 元素的所有子元素,而不是 user 元素。

结果,匹配 user 的模板未被选中。

user 的子级是 personalaccount

选择与这些元素匹配的模板并生成输出。

解决方案:相当多的清理是必要的,但第一个明显的步骤是将上面的代码替换为:

        <xsl:apply-templates select="folktask/member/user"/>

您还必须从已删除的 < 正文中移动 div code>到匹配 folktask/member/user 的模板中。

更正后的 XSLT 代码为:

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

    <xsl:template name="hoo" match="/">
        <html>
            <head>
                <title>Registered Members</title>
                <link rel="stylesheet" type="text/css" href="user.css" />
            </head>
            <body>
                <h1>Registered Members</h1>
                <xsl:apply-templates select="folktask/member/user"/>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="folktask/member/user">
        <div class="userdiv">
            <xsl:apply-templates select="@id"/>
            <xsl:apply-templates select="personal/name"/>
            <xsl:apply-templates select="personal/address1"/>
            <xsl:apply-templates select="personal/city"/>
            <xsl:apply-templates select="personal/county"/>
            <xsl:apply-templates select="personal/postcode"/>
            <xsl:apply-templates select="personal/telephone"/>
            <xsl:apply-templates select="personal/mobile"/>
            <xsl:apply-templates select="personal/email"/>
            <xsl:apply-templates select="personal"/>
            <xsl:apply-templates select="account/username"/>
            <xsl:apply-templates select="account"/>
        </div>
    </xsl:template>

    <xsl:template match="@id">
        <div class="heading bold"><h2>USER ID: <xsl:value-of select="." /></h2></div>
    </xsl:template>

    <xsl:template match="personal/name">
        <div class="small bold">NAME:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/address1">
        <div class="small bold">ADDRESS:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/city">
        <div class="small bold">CITY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/county">
        <div class="small bold">COUNTY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/postcode">
        <div class="small bold">POSTCODE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/telephone">
        <div class="small bold">TELEPHONE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/mobile">
        <div class="small bold">MOBILE:</div>
        <div class="large"><xsl:value-of select="." />
        </div>
    </xsl:template>

    <xsl:template match="personal/email">
        <div class="small bold">EMAIL:</div>
        <div class="large">
            <xsl:element name="a">
                <xsl:attribute name="href">
                    <xsl:text>mailto:</xsl:text>
                    <xsl:value-of select="." />
                </xsl:attribute>
                <xsl:value-of select="." />
            </xsl:element>
        </div>
    </xsl:template>

    <xsl:template match="personal">
    <div class="small bold">SEX:</div>
    <div class="colored bold">
        <xsl:choose>
            <xsl:when test="sex='Male'">
                <div class="sex male"><xsl:value-of select="sex/."/></div>
            </xsl:when>
            <xsl:otherwise>
                <div class="sex female"><xsl:value-of select="sex/."/></div>
            </xsl:otherwise>
        </xsl:choose>
    </div>
    </xsl:template>

    <xsl:template match="account/username">
        <div class="small bold">USERNAME:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>


    <xsl:template match="account">
        <div class="small bold">ACCOUNT TYPE:</div>
        <div class="colored ">
        <xsl:choose>
            <xsl:when test="userlevel='1'">
                <div class="nml bold">Normal User</div>
            </xsl:when>

            <xsl:when test="userlevel='2'">
                <div class="vol bold">Volunteer</div>
            </xsl:when>

            <xsl:when test="userlevel='3'">
                <div class="org bold">Organiser</div>
            </xsl:when>

            <xsl:otherwise>
                <div class="name adm bold">Administrator</div>
            </xsl:otherwise>
        </xsl:choose>
        </div>
    </xsl:template>

</xsl:stylesheet>

运行更正后的转换现在会产生预期结果

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
<title>Registered Members</title>
<link rel="stylesheet" type="text/css" href="user.css">
</head>
<body>
<h1>Registered Members</h1>
<div class="userdiv">
<div class="heading bold"><h2>USER ID: 1</h2></div>
<div class="small bold">NAME:</div>
<div class="large">Abbie Hunt</div>
<div class="small bold">ADDRESS:</div>
<div class="large">108 Access Road</div>
<div class="small bold">CITY:</div>
<div class="large">Wells</div>
<div class="small bold">COUNTY:</div>
<div class="large">Somerset</div>
<div class="small bold">POSTCODE:</div>
<div class="large">BA5 8GH</div>
<div class="small bold">TELEPHONE:</div>
<div class="large">01528927616</div>
<div class="small bold">MOBILE:</div>
<div class="large">07085252492</div>
<div class="small bold">EMAIL:</div>
<div class="large"><a href="mailto:[email protected]">[email protected]</a></div>
<div class="small bold">SEX:</div>
<div class="colored bold">
<div class="sex female">Female</div>
</div>
<div class="small bold">USERNAME:</div>
<div class="large">AdRock</div>
<div class="small bold">ACCOUNT TYPE:</div>
<div class="colored ">
<div class="name adm bold">Administrator</div>
</div>
</div>
<div class="userdiv">
<div class="heading bold"><h2>USER ID: 2</h2></div>
<div class="small bold">NAME:</div>
<div class="large">Aidan Harris</div>
<div class="small bold">ADDRESS:</div>
<div class="large">103 Aiken Street</div>
<div class="small bold">CITY:</div>
<div class="large">Chichester</div>
<div class="small bold">COUNTY:</div>
<div class="large">Sussex</div>
<div class="small bold">POSTCODE:</div>
<div class="large">PO19 4DS</div>
<div class="small bold">TELEPHONE:</div>
<div class="large">01905149894</div>
<div class="small bold">MOBILE:</div>
<div class="large">07784467941</div>
<div class="small bold">EMAIL:</div>
<div class="large"><a href="mailto:[email protected]">[email protected]</a></div>
<div class="small bold">SEX:</div>
<div class="colored bold">
<div class="sex male">Male</div>
</div>
<div class="small bold">USERNAME:</div>
<div class="large">AmbientExpert</div>
<div class="small bold">ACCOUNT TYPE:</div>
<div class="colored ">
<div class="vol bold">Volunteer</div>
</div>
</div>
</body>
</html>

The problem is in this code:

   <xsl:for-each select="folktask/member/user">

        <div class="userdiv">

            <xsl:apply-templates/>

        </div>
    </xsl:for-each>

This applies templates to all children of the current user element -- not to the user element.

As result, the template matching user is not selected.

The children of user are personal and account.

The templates matching these elements are selected and they produce their output.

Solution: Quite some cleanup is necessary, but the first obvious step is to replace the above code with:

        <xsl:apply-templates select="folktask/member/user"/>

You'll also have to move the div from the deleted body of <xsl:for-each> into the template matching folktask/member/user.

The corrected XSLT code is:

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

    <xsl:template name="hoo" match="/">
        <html>
            <head>
                <title>Registered Members</title>
                <link rel="stylesheet" type="text/css" href="user.css" />
            </head>
            <body>
                <h1>Registered Members</h1>
                <xsl:apply-templates select="folktask/member/user"/>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="folktask/member/user">
        <div class="userdiv">
            <xsl:apply-templates select="@id"/>
            <xsl:apply-templates select="personal/name"/>
            <xsl:apply-templates select="personal/address1"/>
            <xsl:apply-templates select="personal/city"/>
            <xsl:apply-templates select="personal/county"/>
            <xsl:apply-templates select="personal/postcode"/>
            <xsl:apply-templates select="personal/telephone"/>
            <xsl:apply-templates select="personal/mobile"/>
            <xsl:apply-templates select="personal/email"/>
            <xsl:apply-templates select="personal"/>
            <xsl:apply-templates select="account/username"/>
            <xsl:apply-templates select="account"/>
        </div>
    </xsl:template>

    <xsl:template match="@id">
        <div class="heading bold"><h2>USER ID: <xsl:value-of select="." /></h2></div>
    </xsl:template>

    <xsl:template match="personal/name">
        <div class="small bold">NAME:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/address1">
        <div class="small bold">ADDRESS:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/city">
        <div class="small bold">CITY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/county">
        <div class="small bold">COUNTY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/postcode">
        <div class="small bold">POSTCODE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/telephone">
        <div class="small bold">TELEPHONE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/mobile">
        <div class="small bold">MOBILE:</div>
        <div class="large"><xsl:value-of select="." />
        </div>
    </xsl:template>

    <xsl:template match="personal/email">
        <div class="small bold">EMAIL:</div>
        <div class="large">
            <xsl:element name="a">
                <xsl:attribute name="href">
                    <xsl:text>mailto:</xsl:text>
                    <xsl:value-of select="." />
                </xsl:attribute>
                <xsl:value-of select="." />
            </xsl:element>
        </div>
    </xsl:template>

    <xsl:template match="personal">
    <div class="small bold">SEX:</div>
    <div class="colored bold">
        <xsl:choose>
            <xsl:when test="sex='Male'">
                <div class="sex male"><xsl:value-of select="sex/."/></div>
            </xsl:when>
            <xsl:otherwise>
                <div class="sex female"><xsl:value-of select="sex/."/></div>
            </xsl:otherwise>
        </xsl:choose>
    </div>
    </xsl:template>

    <xsl:template match="account/username">
        <div class="small bold">USERNAME:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>


    <xsl:template match="account">
        <div class="small bold">ACCOUNT TYPE:</div>
        <div class="colored ">
        <xsl:choose>
            <xsl:when test="userlevel='1'">
                <div class="nml bold">Normal User</div>
            </xsl:when>

            <xsl:when test="userlevel='2'">
                <div class="vol bold">Volunteer</div>
            </xsl:when>

            <xsl:when test="userlevel='3'">
                <div class="org bold">Organiser</div>
            </xsl:when>

            <xsl:otherwise>
                <div class="name adm bold">Administrator</div>
            </xsl:otherwise>
        </xsl:choose>
        </div>
    </xsl:template>

</xsl:stylesheet>

Running the corrected transformation now produces the intended results:

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
<title>Registered Members</title>
<link rel="stylesheet" type="text/css" href="user.css">
</head>
<body>
<h1>Registered Members</h1>
<div class="userdiv">
<div class="heading bold"><h2>USER ID: 1</h2></div>
<div class="small bold">NAME:</div>
<div class="large">Abbie Hunt</div>
<div class="small bold">ADDRESS:</div>
<div class="large">108 Access Road</div>
<div class="small bold">CITY:</div>
<div class="large">Wells</div>
<div class="small bold">COUNTY:</div>
<div class="large">Somerset</div>
<div class="small bold">POSTCODE:</div>
<div class="large">BA5 8GH</div>
<div class="small bold">TELEPHONE:</div>
<div class="large">01528927616</div>
<div class="small bold">MOBILE:</div>
<div class="large">07085252492</div>
<div class="small bold">EMAIL:</div>
<div class="large"><a href="mailto:[email protected]">[email protected]</a></div>
<div class="small bold">SEX:</div>
<div class="colored bold">
<div class="sex female">Female</div>
</div>
<div class="small bold">USERNAME:</div>
<div class="large">AdRock</div>
<div class="small bold">ACCOUNT TYPE:</div>
<div class="colored ">
<div class="name adm bold">Administrator</div>
</div>
</div>
<div class="userdiv">
<div class="heading bold"><h2>USER ID: 2</h2></div>
<div class="small bold">NAME:</div>
<div class="large">Aidan Harris</div>
<div class="small bold">ADDRESS:</div>
<div class="large">103 Aiken Street</div>
<div class="small bold">CITY:</div>
<div class="large">Chichester</div>
<div class="small bold">COUNTY:</div>
<div class="large">Sussex</div>
<div class="small bold">POSTCODE:</div>
<div class="large">PO19 4DS</div>
<div class="small bold">TELEPHONE:</div>
<div class="large">01905149894</div>
<div class="small bold">MOBILE:</div>
<div class="large">07784467941</div>
<div class="small bold">EMAIL:</div>
<div class="large"><a href="mailto:[email protected]">[email protected]</a></div>
<div class="small bold">SEX:</div>
<div class="colored bold">
<div class="sex male">Male</div>
</div>
<div class="small bold">USERNAME:</div>
<div class="large">AmbientExpert</div>
<div class="small bold">ACCOUNT TYPE:</div>
<div class="colored ">
<div class="vol bold">Volunteer</div>
</div>
</div>
</body>
</html>
枕头说它不想醒 2024-09-05 15:03:19

有很多错误。主要有以下几点:

  • 不能将模板应用于属性
  • 如果您编写 ,您可能会编写 来匹配它。 (也适用于其他节点)

There are many errors. The main are the following:

  • You cannot apply template to attribute
  • If you write <xsl:apply-templates select="personal/name"/>, you might write <xsl:template match="name"> to match it. (And also for other nodes)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文