I get the wrong output of my XSLT-file
Posted: Fri Jul 29, 2022 2:17 pm
Hey, I am trying to calculate the percentage of elements in my data, but get the incorrect output. I suppose, it is something wrong with the path, so maybe someone can help me.
Here is the XML-file:
So my XSLT-file tried to calculate how many cars have the normal quantity of kilometres and how much percent have an excess of kilometres, but it doesn't work. Here is my XSLT-file:
Here is the XML-file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<pc:cars
xmlns:pc="some-url-for-pc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="file-on-my-pc.xsd"
version="0.1">
<pc:car url="https://link"
name="Seat Leon"
price="11.700"
year="2015">
<pc:main_descriptions quantity_owner="2"
quantity_of_kilometer="84496">
</pc:main_descriptions>
</pc:car>
</pc:cars>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pc="some-url-for-pc"
exclude-result-prefixes="pc"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/pc:cars">
<xsl:variable name="AmountOfCars" select="count(//pc:car)"/>
<xsl:variable name="Standart" select="16000"/>
<xsl:variable name="high" select="count(pc:car[@quantity_of_kilometer > $Standart])" />
<xsl:variable name="low" select="count(pc:car[@quantity_of_kilometer < $Standart])" />
<html>
<head>
<title>The percentage of kilometres </title>
</head>
<body>
<h1>The percentage of kilometres </h1>
<result>
<highResult>
<xsl:value-of select="format-number($high div $AmountOfCars, '#%')" />
</highResult>
<lowResult>
<xsl:value-of select="format-number($low div $AmountOfCars, '#%')" />
</lowResult>
</result>
</body>
</html>
</xsl:template>
</xsl:stylesheet>