XPath and min function not recognized in xslt

2019-08-17 23:44发布

问题:

<td class="num">
                                        <xsl:if test="min(//vrednostDelnice)=trgovalniPodatki/vrednostDelnice">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//vrednostDelnice)=trgovalniPodatki/vrednostDelnice">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="format-number(trgovalniPodatki/vrednostDelnice, '#.###,00 €', 'euro')"/>
                                    </td>

but I get

This document had an invalid XSLT stylesheet. Error message from the XSLT engine:
Error: XPath expression compilation failed: min(//vrednostDelnice)=trgovalniPodatki/vrednostDelnice
Details: compilation error (characters 1-22, "min(//vrednostDelnice)"): unknown function called: 'min'

Why min is not recognized. Min s valid function: http://www.xsltfunctions.com/xsl/fn_min.html

EDIT:

XSL:

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

XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="odlocitvenProblem.xsl"?>
<delnice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="odlocitvenProblem.xsd">

whole xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:fn="http://www.w3.org/2005/xpath-functions">
    <xsl:output method="xhtml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:decimal-format name="euro" decimal-separator="," grouping-separator="."/>
    <xsl:variable name="kolicnik" select="'1000'"/>
    <xsl:key name="id" match="delnica" use="@id"/>
    <xsl:template match="/">
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
                <title>Delnice - seznam alternativ</title>
                <style type="text/css">
                    body {font: normal 12px/1.6em Arial, Helvetica, sans-serif;color: #2a3845;margin: 0;padding-left: 5px;padding-right: 5px; background: #FFFFFF; width: 100%; }
                    table { margin: 0;padding  0; border: 1px solid #efece7; margin: 0 auto; font : normal 12px/1.6em Arial, Helvetica, sans-serif;color: #2a3845; width: 100%; border-collapse: collapse; }
                    td { border: 1px solid #efece7; padding: 2px; }
                    th { border: 1px solid #efece7; padding: 2px; }
                    td.num { text-align: right;}
                    td.green { text-align: right; color: green;}
                    td.red { text-align: right; color: red;}
                    h1 { color: #7a2e40;margin: 0px 0px 10px 0px;padding-bottom: 10px;font: normal 17px Georgia, serif;border-bottom: 1px solid #efece7;}
                    #wrapper {margin: 0 auto;border-left: 1px solid #f0e9eb;border-right: 1px solid #f0e9eb;}
                    #header {margin: 0 0px; background: #7a2e40;color: #f6dde3; height: 30px;}
                    #main-content { margin: 0 auto; float: left; padding-top: 30px; padding-right: 10px; padding-bottom: 30px; padding-left: 10px;}
                    #footer {background: #f7f7f7; border-top: 1px solid #f0e9eb; border-bottom: 1px solid #f0e9eb; clear: both; height: 30px; }
                    tr.footer { font-size: 10px; vertical-align: top;}
                </style>
            </head>
            <body>
                <div id="wrapper">
                    <div id="header">&#160;</div>
                    <div id="main-content">
                        <h1>Delnice - seznam alternativ</h1>
                        <br/>
                        <table cellspacing="0">
                            <tr>
                                <th rowspan="2"></th>
                                <th rowspan="2">Naziv</th>
                                <th rowspan="2">Kratica</th>
                                <th rowspan="2">Vrednost delnice<br/>
(<xsl:value-of select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='vrednostDelnice']/@utez"/>)
                                </th>
                                <th colspan="3">Sprememba tečaja</th>
                                <th rowspan="2">Vrednost dividende<br/>
(<xsl:value-of select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='vrednostDividende']/@utez"/>)
                                </th>
                                <th rowspan="2">Dividendni donos<br/>
(<xsl:value-of select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='dividendniDonos']/@utez"/>)
                                </th>
                                <th rowspan="2">Promet<br/>
(<xsl:value-of select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='promet']/@utez"/>)
                                </th>
                                <th rowspan="2">Tržna kapitalizacija<br/>
(<xsl:value-of select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='trznaKapitalizacija']/@utez"/>) *
                                </th>
                                <th rowspan="2">Število delnic</th>
                                <th rowspan="2">Čisti dobiček<br/>
(<xsl:value-of select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='cistiDobicek']/@utez"/>) *
                                </th>
                                <th rowspan="2">Finančna sredstva<br/>
(<xsl:value-of select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='financnaSredstva']/@utez"/>) *
                                </th>
                            </tr>
                            <tr>
                                <th>Letna<br/>
(<xsl:value-of select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='zadnjeLeto']/@utez"/>)
                                </th>
                                <th>Mesečna<br/>
(<xsl:value-of select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='zadnjiMesec']/@utez"/>)
                                </th>
                                <th>Dnevna<br/>
(<xsl:value-of select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='zadnjiDan']/@utez"/>)
                                </th>
                            </tr>
                            <xsl:for-each select="/delnice/*">
                                <xsl:sort select="nazivDruzbe"/>
                                <xsl:call-template name="alternative">
                                    <xsl:with-param name="node" select="."/>
                                </xsl:call-template>
                            </xsl:for-each>
                            <tr class="footer">
                                <td></td>
                                <td></td>
                                <td></td>
                                <td><xsl:for-each select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='vrednostDelnice']/zalogaVrednosti">
                                    <xsl:value-of select="@ocena"/>:&#160;<xsl:value-of select="spMeja" /> - <xsl:value-of select="zgMeja" />
                                    <br/>
                                </xsl:for-each></td>
                                <td><xsl:for-each select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='zadnjeLeto']/zalogaVrednosti">
                                    <xsl:value-of select="@ocena"/>:&#160;<xsl:value-of select="spMeja" /> - <xsl:value-of select="zgMeja" />
                                    <br/>
                                </xsl:for-each></td>
                                <td><xsl:for-each select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='zadnjiMesec']/zalogaVrednosti">
                                    <xsl:value-of select="@ocena"/>:&#160;<xsl:value-of select="spMeja" /> - <xsl:value-of select="zgMeja" />
                                    <br/>
                                </xsl:for-each></td>
                                <td><xsl:for-each select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='zadnjiDan']/zalogaVrednosti">
                                    <xsl:value-of select="@ocena"/>:&#160;<xsl:value-of select="spMeja" /> - <xsl:value-of select="zgMeja" />
                                    <br/>
                                </xsl:for-each></td>
                                <td><xsl:for-each select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='vrednostDividende']/zalogaVrednosti">
                                    <xsl:value-of select="@ocena"/>:&#160;<xsl:value-of select="spMeja" /> - <xsl:value-of select="zgMeja" />
                                    <br/>
                                </xsl:for-each></td>
                                <td><xsl:for-each select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='dividendniDonos']/zalogaVrednosti">
                                    <xsl:value-of select="@ocena"/>:&#160;<xsl:value-of select="spMeja" /> - <xsl:value-of select="zgMeja" />
                                    <br/>
                                </xsl:for-each></td>
                                <td><xsl:for-each select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='promet']/zalogaVrednosti">
                                    <xsl:value-of select="@ocena"/>:&#160;<xsl:value-of select="spMeja" /> - <xsl:value-of select="zgMeja" />
                                    <br/>
                                </xsl:for-each></td>
                                <td><xsl:for-each select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='trznaKapitalizacija']/zalogaVrednosti">
                                    <xsl:value-of select="@ocena"/>:&#160;<xsl:value-of select="spMeja div number($kolicnik)" /> - <xsl:value-of select="zgMeja div 1000" />
                                    <br/>
                                </xsl:for-each></td>
                                <td></td>
                                <td><xsl:for-each select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='cistiDobicek']/zalogaVrednosti">
                                    <xsl:value-of select="@ocena"/>:&#160;<xsl:value-of select="spMeja div number($kolicnik)" /> - <xsl:value-of select="zgMeja div 1000" />
                                    <br/>
                                </xsl:for-each></td>
                                <td><xsl:for-each select="document('uteziParametrov.xml')/uteziDelnic/parameter[@naziv='financnaSredstva']/zalogaVrednosti">
                                    <xsl:value-of select="@ocena"/>:&#160;<xsl:value-of select="spMeja div number($kolicnik)" /> - <xsl:value-of select="zgMeja div 1000" />
                                    <br/>
                                </xsl:for-each></td>
                            </tr>
                        </table>
                        <span style="font-size: 80%;">* v <xsl:value-of select="$kolicnik"/></span>
                    </div>
                    <div id="footer">&#160;</div>
                </div>
            </body>
        </html>
    </xsl:template>

    <xsl:template name="alternative">
        <xsl:param name="node"/>
            <tr>
                <td>
                    <xsl:number value="position()" format="1" />
                </td>
                <td>
                    <xsl:value-of select="$node/nazivDruzbe"/>
                </td>
                <td>
                    <xsl:value-of select="kratica"/>
                </td>
                                    <td class="num">
                                        <xsl:if test="fn:min(//vrednostDelnice)=trgovalniPodatki/vrednostDelnice">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//vrednostDelnice)=trgovalniPodatki/vrednostDelnice">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="format-number(trgovalniPodatki/vrednostDelnice, '#.###,00 €', 'euro')"/>
                                    </td>
                                    <td class="num">
                                        <xsl:if test="min(//zadnjeLeto)=trgovalniPodatki/spremembaTecaja/zadnjeLeto">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//zadnjeLeto)=trgovalniPodatki/spremembaTecaja/zadnjeLeto">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="trgovalniPodatki/spremembaTecaja/zadnjeLeto"/>%</td>
                                    <td class="num">
                                        <xsl:if test="min(//zadnjiMesec)=trgovalniPodatki/spremembaTecaja/zadnjiMesec">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//zadnjiMesec)=trgovalniPodatki/spremembaTecaja/zadnjiMesec">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="trgovalniPodatki/spremembaTecaja/zadnjiMesec"/>%</td>
                                    <td class="num">
                                        <xsl:if test="min(//zadnjiDan)=trgovalniPodatki/spremembaTecaja/zadnjiDan">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//zadnjiDan)=trgovalniPodatki/spremembaTecaja/zadnjiDan">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="trgovalniPodatki/spremembaTecaja/zadnjiDan"/>%</td>
                                    <td class="num">
                                        <xsl:if test="min(//vrednostDividende)=trgovalniPodatki/vrednostDividende">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//vrednostDividende)=trgovalniPodatki/vrednostDividende">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="trgovalniPodatki/vrednostDividende"/>
                                    </td>
                                    <td class="num">
                                        <xsl:if test="min(//dividendniDonos)=trgovalniPodatki/dividendniDonos">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//dividendniDonos)=trgovalniPodatki/dividendniDonos">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="trgovalniPodatki/dividendniDonos"/>%</td>
                                    <td class="num">
                                        <xsl:if test="min(//promet)=trgovalniPodatki/promet">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//promet)=trgovalniPodatki/promet">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="trgovalniPodatki/promet"/>
                                    </td>
                                    <td class="num">
                                        <xsl:if test="min(//trznaKapitalizacija)=trgovalniPodatki/trznaKapitalizacija">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//trznaKapitalizacija)=trgovalniPodatki/trznaKapitalizacija">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="format-number(trgovalniPodatki/trznaKapitalizacija div number($kolicnik), '###.###.###', 'euro')"/>
                                    </td>
                                    <td class="num">
                                        <xsl:value-of select="financniPodatki/steviloDelnic"/>
                                    </td>
                                    <td class="num">
                                        <xsl:if test="min(//cistiDobicek)=financniPodatki/cistiDobicek">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//cistiDobicek)=financniPodatki/cistiDobicek">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="financniPodatki/cistiDobicek div number($kolicnik)"/>
                                    </td>
                                    <td class="num">
                                        <xsl:if test="min(//financnaSredstva)=financniPodatki/financnaSredstva">
                                            <xsl:attribute name="class">red</xsl:attribute>
                                        </xsl:if>
                                        <xsl:if test="max(//financnaSredstva)=financniPodatki/financnaSredstva">
                                            <xsl:attribute name="class">green</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="financniPodatki/financnaSredstva div number($kolicnik)"/>
            </td>
        </tr>
    </xsl:template>
</xsl:stylesheet>

回答1:

The min function is part of XSLT and XPath 2.0 and that way is supported by XSLT 2.0 processors like Saxon 9, AltovaXML or XmlPrime. Inside the browser there is no support for XSLT 2.0 unless you use Saxon-CE. So the error you get simply means that you are trying to run XSLT 2.0 code with an XSLT 1.0 processor.



回答2:

Saying that your stylesheet is a version 2.0 stylesheet isn't going to help if the XSLT processor you invoke only understands XSLT 1.0. I don't recognize the error messages you are getting, and there are no other clues in your post as to which XSLT processor you are using, but it does appear to be an XSLT 1.0 processor. Tell us how you are running the transform, e.g. from the command line, from the browser, or from an application in some programming language.