×
Creating solutions

Error : Unexpected XSLT element 'param'

Pri práci s parametrami v jazyku XSLT s použitím PHP sa môže používateľ stretnúť s chybovým hlásením XSLTProcessor::transformToXml(): Unexpected XSLT element 'param'. Toto hlásenie sa zobrazí, ak je definícia parametra umiestnená na nesprávnom mieste v dokumente *.xsl.
Definícia parametrov musí byť uvedená hneď za definíciou šablóny <xsl:template>. V prípade, že tomu tak nie je, používateľ dostane chybové hlásenie Unexpected XSLT element 'param' a transformácia sa nevykoná. Pri kombinácii XSLT a PHP, kde transformáciu vykonáva metóda transformToXml(), je hlásenie v znení XSLTProcessor::transformToXml(): Unexpected XSLT element 'param'.
Príklad: Nesprávne umiestnenie definície parametra v dokumente *.xsl.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="html">
<h1>
<xsl:value-of select="title"/>
</h1>
<xsl:param name="my-parameter" select="title"/>
<xsl:value-of select="$my-parameter"/>
</xsl:template>
</xsl:stylesheet>
V uvedenom príklade je definícia parametra umiestnená až za element <h1>. Definícii parametra nesmie predchádza žiaden iný <xsl> element alebo element jazyka HTML.
Príklad: Správne umiestnenie definície parametra v dokumente *.xsl.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="html">
<xsl:param name="my-parameter" select="title"/>
<h1>
<xsl:value-of select="title"/>
</h1>
<xsl:value-of select="$my-parameter"/>
</xsl:template>
</xsl:stylesheet>

Záver

Okrem parametrov môže používateľ definovať aj premenné. Ich umiestnenie nie je viazané na pozíciu definície šablóny.
Autor: Matej Lednár
Dátum: 22.2.2013
Kategória: XML
Značky: xslt, xml, error, programovanie, php, html


XML,XSLT,XML,error,programovanie,PHP,HTML
No part of this article may be reproduced without mention of the author and URL to this website.
For more information, see the About section.

Comments

Article has no comments.

Add a comment

Name (required)
Website
Message (required)
Submit
From latest