xslt_process

xslt_process -- Transformovat XML data řetězcem obsahujícím XSL data

Popis

mixed xslt_process ( resource xh, string xml, string xsl [, string result [, array arguments [, array parameters]]])

xslt_process( ) přijímá jako první argument řetězec obsahující XSLT stylesheet , jako druhý argument řetězec obsahující XML data , která chcete transformovat , a jako třetí argument řetězec obsahujícící výsledky transformace . xslt_process( ) vrací TRUE při úspěchu a FALSE při selhání . Číslo a text chyby případně vzniklé při transformaci můžete získat pomocí xslt_errno( ) a xslt_error( ) funkcí .

Příklad 1 . Použití xslt_process( ) k transformaci tří řetězců

 
?php

 
$xslData

 
=

 
'

 
 xsl:stylesheet

 
version="1.0

 
"

 
xmlns:xsl="http

 
:

 
/

 
/www.w3.org

 
/

 
1999

 
/

 
XSL

 
/

 
Transform

 
"

 
xsl:template

 
match="article

 
"

 
table

 
border="1

 
"

 
cellpadding="2

 
"

 
cellspacing="1

 
"

 
tr

 
td

 
width="20%

 
"

 
/

 
title

 
td

 
width="80%

 
"

 
h2

 
xsl:value-of

 
select="title

 
"

 
/

 
h2

 
h3

 
xsl:value-of

 
select="author

 
"

 
/

 
h3

 
br

 
xsl:value-of

 
select="body

 
"

 
/

 
td

 
/

 
tr

 
/

 
table

 
/

 
xsl:template

 
/

 
xsl:stylesheet

 
'

 
;

 
$xmlData

 
=

 
'

 
?xml

 
version="1.0"

 
?

 
article

 
title

 
Learning

 
German

 
/

 
title

 
author

 
Sterling

 
Hughes

 
/

 
author

 
body

 
Essential

 
phrases

 
:

 
br

 
br

 
Komme

 
sie

 
mir

 
sagen

 
,

 
woe

 
die

 
toilette

 
es

 
?

 
br

 
Eine

 
grande

 
beer

 
bitte

 
!

 
br

 
Noch

 
einem

 
bitte

 
.

 
br

 
/

 
body

 
/

 
article

 
'

 
;

 
if

 
(xslt_process($xslData

 
,

 
$xmlData

 
,

 
$result)

 
)

 
{

 
echo

 
"Here

 
is

 
the

 
brilliant

 
in-depth

 
article

 
on

 
learning"

 
;

 
echo

 
"

 
German

 
:

 
"

 
;

 
echo

 
"

 
br

 
\n

 
br

 
"

 
;

 
echo

 
$result

 
;

 
}

 
else

 
{

 
echo

 
"There

 
was

 
an

 
error

 
that

 
occurred

 
in

 
the

 
XSL

 
transformace...\n"

 
;

 
echo

 
"\tError

 
number

 
:

 
"

 
.

 
xslt_errno(

 
)

 
.

 
"\n"

 
;

 
echo

 
"\tError

 
string

 
:

 
"

 
.

 
xslt_error(

 
)

 
.

 
"\n"

 
;

 
exit

 
;

 
}

 
?