XSLT根本没有改变XML

时间:2017-04-27 20:08:37

标签: xml xslt

我得到了这个错误:转换为XSLT时出错。 XSLT 1.0中属性的值无效。 我是XSLT和XML的新手,所以请原谅我的无知,但我搜索了错误,但没有找到它。我只在mozilla中得到这个错误,在IE中,它仅使用完全忽略XSLT的CSS文件来修改XML。 所以,这是我的XML和XSLT代码:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="pti_project.css"?>
<?xml-stylesheet type="text/xsl" href="pti_projec.xslt"?>
<people>
    <employee>
        <name>Ivan</name>
        <family>Ivanov</family>
        <number>0928345768</number>
        <section>1</section>
        <salary>1200</salary>
        <yearofbirth>1997</yearofbirth>
        <numchildren>3</numchildren>
    </employee>
    <employee>
        <name>Petar</name>
        <family>Ivanov</family>
        <number>0384578394</number>
        <section>2</section>
        <salary>800</salary>
        <yearofbirth>1990</yearofbirth>
        <numchildren>1</numchildren>
    </employee>
    <employee>
        <name>Sierra</name>
        <family>Sierra</family>
        <number>0398493821</number>
        <section>1</section>
        <salary>1100</salary>
        <yearofbirth>1999</yearofbirth>
        <numchildren>0</numchildren>
    </employee>
    <employee>
        <name>Cayla</name>
        <family>Siver</family>
        <number>0232452875</number>
        <section>1</section>
        <salary>1300</salary>
        <yearofbirth>1999</yearofbirth>
        <numchildren>0</numchildren>
    </employee>
    <employee>
        <name>Sara</name>
        <family>Silver</family>
        <number>0723845377</number>
        <section>2</section>
        <salary>1500</salary>
        <yearofbirth>1991</yearofbirth>
        <numchildren>3</numchildren>
    </employee>
    <employee>
        <name>Mark</name>
        <family>Goldenberg</family>
        <number>0932834571</number>
        <section>2</section>
        <salary>700</salary>
        <yearofbirth>1989</yearofbirth>
        <numchildren>2</numchildren>
    </employee>
    <employee>
        <name>Henry</name>
        <family>Siver</family>
        <number>0837465737</number>
        <section>2</section>
        <salary>1400</salary>
        <yearofbirth>1994</yearofbirth>
        <numchildren>0</numchildren>
    </employee>
    <employee>
        <name>Bobbie</name>
        <family>Silver</family>
        <number>0654739725</number>
        <section>3</section>
        <salary>1000</salary>
        <yearofbirth>1997</yearofbirth>
        <numchildren>3</numchildren>
    </employee>
    <employee>
        <name>Pennie</name>
        <family>River</family>
        <number>0832888216</number>
        <section>3</section>
        <salary>650</salary>
        <yearofbirth>1999</yearofbirth>
        <numchildren>0</numchildren>
    </employee>
    <employee>
        <name>Leonardo</name>
        <family>Splinter</family>
        <number>0832838477</number>
        <section>3</section>
        <salary>1800</salary>
        <yearofbirth>1995</yearofbirth>
        <numchildren>2</numchildren>
    </employee>
</people>

这是XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
    <body>
        <table border="2">
            <tr>
                <th>
                    Name:
                </th>
                <th>
                    Family:
                </th>
                <th>
                    Number:
                </th>
                <th>
                    Section:
                </th>
                <th>
                    Salary:
                </th>
                <th>
                    Year of birth:
                </th>
                <th>
                    Number of children:
                </th>
            </tr>
            <xsl:for-each select="people/employee">
            <xsl:sort select="name" data-type="text" order="acsending"/>
            <tr>
                <xsl:choose>
                    <xsl:when test="salary&gt;200">
                        <td color="green">
                            <xsl:value-of select="name"/>
                        </td>
                        <td>
                            <xsl:value-of select="family"/>
                        </td>
                        <td>
                            <xsl:value-of select="number"/>
                        </td>
                        <td>
                            <xsl:value-of select="section"/>
                        </td>
                        <td>
                            <xsl:value-of select="salary"/>
                        </td>
                        <td>
                            <xsl:value-of select="yearofbirth"/>
                        </td>
                        <td>
                            <xsl:value-of select="numchildren"/>
                        </td>
                    </xsl:when>
                </xsl:choose>
            </tr>
        </xsl:for-each>
    </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

很抱歉发布了这么多。

2 个答案:

答案 0 :(得分:0)

您需要更改:

order="acsending"

为:

order="ascending"

您还需要一个更好的测试工具。

P.S。另请注意,color不是td的有效属性。但这与XSLT无关。

答案 1 :(得分:-1)

你不能使用&lt;和&gt;在xml / xsl文档中,除了分隔标记。这样:

<xsl:when test="salary>200">

应该是:

<xsl:when test="salary&gt;200">