Professional Documents
Culture Documents
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 2
Como funciona
Um programa XSL usado por um
Processador de XSLT para transformar
um dado documento XML
Quer o XML quer o XSL so documentos
recebidos pelo Processar
O resultado outro ficheiro XML com uma
nova estrutura e cujo contedo, ou parte
deste, pode ter sido ou no
alterado/filtrado/substitudo
o Em grande parte das vezes o resultado um XML com
marcas (tags
(tags)) do HTML 4.0, ou seja um xHTML
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 3
XSLT Processor
Saxon XML
Xalan xhtml
XML Sablotron XSL-FO
IE Text*
FF
Processador
XML
XSLT
XSLT
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 4
Resultado da Transformao
o Em situaes especiais o resultado pode ser um HTML
ou um documento de texto ou mesmo um RTF
o Pode ainda ser um XSL-
XSL-FO que pode posteriormente
ser transformado por um processador de XSL-
XSL-FO (FOP
por exemplo) em PDF ou em Postscript
o Em circunstncias muito especiais pode ser um novo
XSL. Estamos neste caso em presena de um XSL de 2
gerao.
o Na maioria das vezes um XML com uma estrutura
diferente mantendo o mesmo contedo. usado em
casos onde necessrio converter uma estrutura numa
outra.
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 5
Ns
Do ponto de vista do Processador XSL
tudo so Ns
Cada documento XML tem um N Raiz, cujo
contedo o documento inteiro
o Debaixo deste temos as instrues de
processamento (se presentes) e o N Elemento
Raiz
O N Elemento Raiz contm todos os outros
Ns Elemento, Ns Atributo e Ns texto
o Um documento XML bem formado s pode ter um
N Elemento Raiz
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 6
Tipos de Ns
<?xml version="1.0" encoding="UTF-8"?>
N Elemento <?xml-stylesheet type="text/xsl" href="ex1.xsl"?> N Instruo de
Raiz <curso nome="LCI"> Processamento
<disciplina nome="II" semestre="1">
<docente>
<nome>Joo</nome>
<email>j@fe.up.pt</email> N Atributo
</docente>
<alunos>
<aluno> N Texto
N Elemento <nome>Ana</nome>
<email>a@fe.up.pt</email>
</aluno>
<aluno>
<nome>Rita</nome>
<email>r@fe.up.pt</email>
</aluno>
<aluno/>
</alunos>
</disciplina>
</curso>
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 7
Estrutura em rvore e Tipos de Ns
N Raiz
N Elemento
Curso Raiz N
Elemento
nome=LCI disciplina
nome=II
semestre=1 alunos
N Atributo N Texto
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 8
Elemento Raiz de um XSLT
ex1.xsl
</xsl:stylesheet>
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 10
Resultado da Transformao 1
Curso
nome=LCI disciplina
nome=II XALAN
semestre=1 alunos
a@fe.up r@fe.up
Joo j@fe.up.pt Ana Rita
.pt .pt
ex1.xsl
Result
<?xml version="1.0" encoding="UTF-8"?>
Jooj@fe.u.ptAnaa@fe.up.ptRitar@fe.up.pt
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 11
Anlise do resultado
Como o XSLT s tem o elemento raiz o
Processador aplica as regras por omisso
De uma forma muito simplista pode-
pode-se dizer que:
o a regra por omisso : cada N Elemento
transformado no seu contedo de texto
o Os Ns Atributo so ignorados
Adiante reformularemos esta definio
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 12
Definio de Regras
<?xml version="1.0" encoding="UTF-8"?>
ex2.xsl
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 15
Obteno do valor de um N
<?xml version="1.0" encoding="UTF-8"?>
ex2.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Boa prtica:
<xsl:template match="nome">
<div style="margin:1px"> O N Elemento
<xsl:value-of select="."/>
</div> Raiz (ou,
</xsl:template>
<xsl:template match=/curso">
alternativamente,
<html>
<head>
o N Raiz) deve
<title>ex4</title> ser transformado
</head>
<body>Curso</body> no N Elemento
</html>
</xsl:template> Raiz do Resultado
</xsl:stylesheet>
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 18
Anteviso de um Problema
Neste ltimo exemplo o N Elemento Raiz
(curso) vai ser transformado em
<html>
<head>
<title>ex4</title>
</head>
<body>Curso</body>
</html>
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 19
Problema!?
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
ex4.xsl
</xsl:template>
</aluno></alunos></disciplina>
</xsl:stylesheet> <head>
<title>ex4</title> </curso>
</head>
<body>Curso</body>
</html>
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 20
Modus operandis
O Processador de XSL(T) comea por
transformar o N Raiz do documento XML
Transforma
Transforma--o de acordo com a regra definida
o Caso no exista usa a regra omissa
A regra omisso para o N Raiz e para qualquer N
Elemento : aplicar Regras aos Ns Filho
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="nome">
<div style="margin:1px"> iii
<xsl:value-of select="."/>
</div>
</xsl:template>
<xsl:template match="curso">
<html>
<body>
<xsl:apply-templates select="*"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 23
Aplicao de Regras a Ns Filho
Para explicitamente aplicar regras aos Ns Elemento Filho usa-
se o elemento apply-template com o atributo select contendo
uma expresso Xpath ('*, neste caso) que selecciona todos os
Ns Elemento Filho
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 24
Aplicao de Regras a Ns Filho
<?xml version="1.0" encoding="UTF-8"?>
ex6.xsl
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 26
Obteno do nome do N
<?xml version="1.0" encoding="UTF-8"?>
ex8.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
A funo
<xsl:template match="nome|email">
<div>
name()
name()
<xsl:value-of select="name()"/>:<xsl:value-of select="."/>
</div> permite obter
</xsl:template>
<xsl:template match="curso"> o nome do n
<html>
<body> corrente
<xsl:apply-templates select="*"/>
</body>
</html> uma funo
</xsl:template>
</xsl:stylesheet> Xpath
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 27
Obteno do nome do N
<?xml version="1.0" encoding="UTF-8"?>
ex8.xsl
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 29
Regra mais especfica
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
ex9.xsl
<html>
<div>nome:Joo</div> </curso>
<body>
<xsl:apply-templates select="*"/> <div>email:j@fe.up.pt</div>
</body> <div style="color:red">nome:Ana</div>
</html> <div>email:a@fe.up.pt</div>
</xsl:template> <div style="color:red">nome:Rita</div>
</xsl:stylesheet> <div>email:r@fe.up.pt</div>
08
08-
-11
11-
-10
</body></html>
http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 30
Incluir os Atributos
A regra omissa para os elementos no aplica
regras aos Atributos
Quando usamos o apply-
apply-templates temos de
indicar se s queremos os N Elemento filho
(*) ou tambm os Ns Atributo filho (@*)
A regra omissa para os atributos obter o
seu valor
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 31
Incluir os Atributos
<?xml version="1.0" encoding="UTF-8"?>
ex10.xsl
Resultado
</xsl:template> </aluno>
<xsl:template match="curso"> <body>LCI <aluno>
<html> <div>nome:Joo</div>
<nome>Rita</nome>
<body> <div>email:j@fe.up.pt</div>
<email>r@fe.up.pt</email>
<xsl:apply-templates select="*|@*"/> </aluno></alunos></disciplina></curso
<div style="color:red">nome:Ana</div>
</body> <div>email:a@fe.up.pt</div>
</html> <div style="color:red">nome:Rita</div>
</xsl:template> <div>email:r@fe.up.pt</div>
</xsl:stylesheet> </body>
08
08-
-11
11-
-10 </html>
http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 32
Regras Omissas (verso final)
Cada N Texto transformado no seu valor
Cada N Atributo transformado no seu
valor
Cada N Elemento Transformado no
resultado da transformao dos seus Ns
Elementos filho e dos seus Ns Texto filho
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 33
Regras omissas explicitadas
<?xml version="1.0" encoding="UTF-8"?>
Ex11.xsl
<email>r@fe.up.pt</email>
</aluno>
</alunos>
</disciplina>
</curso>
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 34
Atributos com valores dinmicos
Quando queremos gerar um elemento com um valor
dinmico usamos o elemento value
value--of,
of, EX:
<div>
div>
<xsl:value
xsl:value--of select=.>
select=.>
</div
</div>>
08
08-
-11
11-
-10 http://www.fe.up.pt/~jvv/Assuntos/XSL/xsl.pdf 35
Atributos com valores dinmicos
<?xml version="1.0" encoding="UTF-8"?>
Ex11.xsl
<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>
Passo 2: escrever as regras
/ /
Alunos html
aluno aluno body
nome email nome email table
Rute r@m.pt Lusa l@m.pt tr tr
td td td td
Rute r@m.pt Lusa l@m.pt
<xsl:template match="nome|email">
<td>
<xsl:apply-templates select="node()"/>
</td>
</xsl:template>
Passo 2: escrever as regras
/ /
Alunos html
aluno aluno body
nome email nome email table
Rute r@m.pt Lusa l@m.pt tr tr
td td td td
Rute r@m.pt Lusa l@m.pt
<xsl:template match=aluno">
<tr>
<xsl:apply-templates select="node()"/>
</tr>
</xsl:template>
Passo 2: escrever as regras
/ /
Alunos html
aluno aluno body
nome email nome email table
Rute r@m.pt Lusa l@m.pt tr tr
td td td td
Rute r@m.pt Lusa l@m.pt
<xsl:template match="Alunos">
<html>
<body>
<table>
<xsl:apply-templates select="node()"/>
</table>
</body>
</html>
</xsl:template>
Resultado Final
<Alunos> <xsl:stylesheet version="1.0"
<aluno> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<nome>Rute</nome> <xsl:template match="Alunos">
<email>r@m.pt</email> <html>
</aluno> <body>
<aluno> <table>
<nome>Lusa</nome> <xsl:apply-templates select="node()"/>
<email>l@m.pt</email> </table>
</aluno> </body>
</Alunos> </html>
</xsl:template>
<xsl:template match=aluno">
<html> <tr>
<body> <xsl:apply-templates select="node()"/>
<table> </tr>
<tr> </xsl:template>
<td>Rute</td> <xsl:template match="nome|email">
<td>r@m.pt</td> <td>
</tr> <xsl:apply-templates select="node()"/>
<tr> </td>
<td>Rute</td> </xsl:template>
<td>r@m.pt</td> <xsl:template match="text()">
</tr> <xsl:value-of select="."/>
</table> </xsl:template>
</body> </xsl:stylesheet>
</html>
Mapeamentos
Alternativos
Um mapeamento alternativo
/ /
Alunos html
aluno aluno body
nome email nome email table
Rute r@m.pt Lusa l@m.pt tr tr
td td td td
Rute r@m.pt Lusa l@m.pt
<xsl:template match="nome|email">
<td>
<xsl:value-of select=text()"/>
</td>
</xsl:template>
Resultado Final
<Alunos> <xsl:stylesheet version="1.0"
<aluno> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<nome>Rute</nome> <xsl:template match="Alunos">
<email>r@m.pt</email> <html>
</aluno> <body>
<aluno> <table>
<nome>Lusa</nome> <xsl:apply-templates select="node()"/>
<email>l@m.pt</email> </table>
</aluno> </body>
</Alunos> </html>
</xsl:template>
<xsl:template match=aluno">
<html> <tr>
<body> <xsl:apply-templates select="node()"/>
<table> </tr>
<tr> </xsl:template>
<td>Rute</td> <xsl:template match="nome|email">
<td>r@m.pt</td> <td>
</tr> <xsl:value-of select=text()"/>
<tr> </td>
<td>Rute</td> </xsl:template>
<td>r@m.pt</td> </xsl:stylesheet>
</tr>
</table>
</body>
</html>
Outro mapeamento alternativo
/ /
Alunos html
aluno aluno body
nome email nome email table
Rute r@m.pt Lusa l@m.pt tr tr
td td td td
Rute r@m.pt Lusa l@m.pt
<xsl:template match=aluno">
<tr>
<td>
<xsl:value-of select=nome/text()"/>
</td>
<td>
<xsl:value-of select=email/text()"/>
</td>
</tr>
</xsl:template>
Resultado Final
<Alunos> <xsl:stylesheet version="1.0"
<aluno> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<nome>Rute</nome> <xsl:template match="Alunos">
<email>r@m.pt</email> <html>
</aluno> <body>
<aluno> <table>
<nome>Lusa</nome> <xsl:apply-templates select="node()"/>
<email>l@m.pt</email> </table>
</aluno> </body>
</Alunos> </html>
</xsl:template>
<xsl:template match=aluno">
<html> <tr>
<body> <td>
<table> <xsl:value-of select=nome/text()"/>
<tr> </td>
<td>Rute</td> <td>
<td>r@m.pt</td> <xsl:value-of select=email/text()"/>
</tr> </td>
<tr> </tr>
<td>Rute</td> </xsl:template>
<td>r@m.pt</td> </xsl:stylesheet>
</tr>
</table>
</body>
</html>
Mais elementos e
funes do XSLT
Copiar Ns um a um
<?xml version="1.0"?> <?xml version="1.0"?>
Result.xml
Ex1.xml
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> O elemento
<xsl:template match="node()|@*">
<xsl:copy>
xsl:copy copia o N
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Copiar sub-rvore
<?xml version="1.0"?> <?xml version="1.0?>
Result.xml
Ex1.xml
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template> O elemento xsl:copy-of copia a sub-
<xsl:template match="@y"/> rvore indicada no atributo select
<xsl:template match="a[2]">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
Inst. de processamento
<?xml version="1.0"?> <?xml version="1.0"?>
Result.xml
Ex1.xml
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*"> A funo processing-
<xsl:copy> instruction() devolve
<xsl:apply-templates select="node()|@*"/> os Ns Instruo de
</xsl:copy> Processamento
</xsl:template>
<xsl:template match="processing-instruction()"/>
</xsl:stylesheet>
Comentrios
<?xml version="1.0"?> <?xml version="1.0"?>
Result.xml
Ex1.xml
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> comment()
<xsl:template match="node()|@*"> devolve os Ns
<xsl:copy> comentrio
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="processing-instruction()|comment()"/>
</xsl:stylesheet>
Gerao de comentrios
Result.xml
Ex1.xml
Result.xml
Ex1.xml
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy> O elemento xsl:processing-instruction
</xsl:template>
<xsl:template match="comment()"/> gera um N Instruo de Processamento
<xsl:template match="/">
<xsl:processing-instruction name="xml-stylesheet">href="style.css"
type="text/css"</xsl:processing-instruction>
<xsl:apply-templates select="*"/>
</xsl:template></xsl:stylesheet>
Gerao de Elementos
<?xml version="1.0"?> <?xml version="1.0" encoding="utf-8"?>
Result.xml
Ex1.xml
<R> <R>
<a> <a>
<b x="0" y="1"/> <b><x>0</x><y>1</y></b>
<b x="2" y="3"/> <b><x>2</x><y>3</y></b>
</a> </a>
<a> <a>
<c x="0" y="1"/> <c><x>0</x><y>1</y></c>
<c x="2" y="3"/> <c><x>2</x><y>3</y></c>
</a> </a>
</R> </R>
Elementos
gerados pelo XSLT
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:element name="{name()}">
<xsl:value-of select="."/> O elemento xsl:element gera
</xsl:element> um N Elemento cujo nome
</xsl:template> indicado no atributo name
</xsl:stylesheet>
Gerao de Atributos
<?xml version="1.0?> <?xml version="1.0"?>
Result.xml
Ex1.xml
<R> <R>
<a> <a>
<b><x>0</x><y>1</y></b> <b x="0" y="1"/>
<b><x>2</x><y>3</y></b> <b x="2" y="3"/>
</a> </a>
<a> <a>
<c><x>0</x><y>1</y></c> <c x="0" y="1"/>
<c><x>2</x><y>3</y></c> <c x="2" y="3"/>
</a> </a>
</R> </R>
Atributos gerados
pelo XSLT
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(*)]">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/> O elemento xsl:attribute gera
</xsl:attribute> um N Atributo cujo nome
</xsl:template> indicado no atributo name
</xsl:stylesheet>
Gerao de IDs
<?xml version="1.0"?> <?xml version="1.0" encoding="utf-
Result.xml
Ex1.xml
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template> A funo generate-id gera
<xsl:template match="*"> um valor nico dentro do
<xsl:copy> documento resultante
<xsl:attribute name="ID">
<xsl:value-of select="generate-id()"/>
</xsl:attribute>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Espaos de Nomes: problema
<R xmlns="urn:feup-isi"> <R xmlns="urn:feup-isi">
Result.xml
Ex1.xml
<a> <a>
<b x="0" y="1"/> <b x="0" y="1"/>
<b x="2" y="3"/> <b x="2" y="3"/>
</a> </a>
<a> <a>
<c x="0" y="1"/> <c x="0" y="1"/>
<c x="2" y="3"/> <c x="2" y="3"/>
</a> </a>
</R> Espao de nomes </R>
por omisso
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
Ex1.xsl
<xsl:apply-templates select="node()|@*"/>
</xsl:copy> No surge no
</xsl:template>
<xsl:template match="b"> resultado!
<bbb> Porque?
<xsl:apply-templates select="node()|@*"/>
</bbb>
</xsl:template> O elemento b do espao de nomes
</xsl:stylesheet> annimo e no documento XML fonte
os elementos so todos do espao
de nomes urn:feup-isi
Indicao do Espao de Nomes
<R <R xmlns="urn:feup-isi">
Result.xml
Ex1.xml
xmlns="urn:feup-isi"> <a>
<a> <bbb xmlns="" xmlns:fe="urn:feup-isi" x="0" y="1"/>
<b x="0" y="1"/> <bbb xmlns="" xmlns:fe="urn:feup-isi" x="2" y="3"/>
<b x="2" y="3"/> </a>
</a> <a>
<a> <c x="0" y="1"/>
<c x="0" y="1"/> <c x="2" y="3"/>
<c x="2" y="3"/> </a>
</a> </R>
</R>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fe="urn:feup-isi">
<xsl:template match="node()|@*">
<xsl:copy>
Ex1.xsl
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="fe:b">
<bbb>
<xsl:apply-templates select="node()|@*"/>
</bbb>
</xsl:template>
</xsl:stylesheet>
Espao de Nomes annimo
<R <R xmlns="urn:feup-isi">
Result.xml
Ex1.xml
xmlns="urn:feup-isi"> <a>
<a> <bbb xmlns="" xmlns:fe="urn:feup-isi" x="0" y="1"/>
<b x="0" y="1"/> <bbb xmlns="" xmlns:fe="urn:feup-isi" x="2" y="3"/>
<b x="2" y="3"/> </a>
</a> <a>
<a> <c x="0" y="1"/>
<c x="0" y="1"/> <c x="2" y="3"/>
<c x="2" y="3"/> </a>
</a> </R>
</R>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fe="urn:feup-isi">
<xsl:template match="node()|@*">
<xsl:copy>
Ex1.xsl
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template> O elemento bbb criado no
<xsl:template match="fe:b"> espao de nomes annimo
<bbb>
<xsl:apply-templates select="node()|@*"/>
</bbb>
</xsl:template>
</xsl:stylesheet>
Criao de Elementos no Espao de Nomes annimo
<R xmlns="urn:feup-isi"> <R xmlns="urn:feup-isi">
Result.xml
Ex1.xml
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fe="urn:feup-isi">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template> O elemento aaa criado no
<xsl:template match="fe:a"> espao de nomes annimo
<aaa>
<xsl:apply-templates select="node()|@*"/>
</aaa>
</xsl:template>
</xsl:stylesheet>
Criao de Elementos no Espao de Nomes do documento
<R xmlns="urn:feup-isi"> <R xmlns="urn:feup-isi">
Result.xml
Ex1.xml
<xsl:stylesheet version="1.0"
Ex1.xsl
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fe="urn:feup-isi">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template> O elemento aaa criado no espao
<xsl:template match="fe:a"> de nomes do documento
<fe:aaa>
<xsl:apply-templates select="node()|@*"/>
</fe:aaa>
</xsl:template>
</xsl:stylesheet>
Criao de Elementos no Espao de Nomes do documento
<R xmlns="urn:feup-isi"> <R xmlns="urn:feup-isi">
Result.xml
Ex1.xml
<xsl:stylesheet version="1.0"
Ex1.xsl
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fe="urn:feup-isi">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template> O elemento aaa criado no espao
<xsl:template match="fe:a"> de nomes do documento
<aaa xmlns="urn:feup-isi">
<xsl:apply-templates select="node()|@*"/>
</aaa>
</xsl:template>
</xsl:stylesheet>
Criao de Elementos no Espao de Nomes do documento
<R xmlns="urn:feup-isi"> <R xmlns="urn:feup-isi">
Result.xml
Ex1.xml
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fe="urn:feup-isi">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="fe:a">
<aaa xmlns="urn:feup-isi">
<xsl:apply-templates select="node()|@*"/>
</aaa>
</xsl:template>
</xsl:stylesheet>
O xsl:element e o Espao de Nomes
<R xmlns="urn:feup-isi"> <R xmlns="urn:feup-isi">
Result.xml
Ex1.xml
<a> <aaa>
<b x="0" y="1"/> <b x="0" y="1"/>
<b x="2" y="3"/> <b x="2" y="3"/>
</a> </aaa>
<a> <aaa>
<c x="0" y="1"/> <c x="0" y="1"/>
<c x="2" y="3"/> <c x="2" y="3"/>
</a> </aaa>
</R> </R>
<xsl:stylesheet version="1.0"
Ex1.xsl
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fe="urn:feup-isi">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy> O espao de nomes do elemento
</xsl:template>
<xsl:template match="fe:a"> indicado no atributo namespace
<xsl:element name="aaa" namespace="urn:feup-isi">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
O xsl:element e o Espao de Nomes
<R xmlns="urn:feup-isi"> <R xmlns="urn:feup-isi">
Result.xml
Ex1.xml
<xsl:stylesheet version="1.0"
Ex1.xsl
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fe="urn:feup-isi">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="fe:a">
<xsl:element name="pr:aaa" namespace="urn:feup-isi">
<xsl:apply-templates select="node()|@*"/>
</xsl:element> Este prefixo automaticamente associado aos
</xsl:template>
</xsl:stylesheet>
espao de nomes indicado no atributo namespace
Qualquer Espao de Nomes
<R xmlns="urn:feup-isi"> <R xmlns="urn:feup-isi">
Result.xml
Ex1.xml
<a> <aaa>
<b x="0" y="1"/> <b x="0" y="1"/>
<b x="2" y="3"/> <b x="2" y="3"/>
</a> </aaa>
<a xmlns=""> <aaa xmlns="">
<c x="0" y="1"/> <c x="0" y="1"/>
<c x="2" y="3"/> <c x="2" y="3"/>
</a> </aaa>
</R> </R>
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy> A funo local-name
<xsl:apply-templates select="node()|@*"/> devolve o nome do
</xsl:copy> N sem o prefixo
</xsl:template>
<xsl:template match="*[local-name()='a']">
<xsl:element name="aaa" namespace="{namespace-uri()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
A funo namespace-uri devolve
</xsl:stylesheet> o espao de nomes do N