Copy e Copy-das construções em XSL |
Copy e cópia-das construções
|
O copy e cópia-das construções é usado copí os nós. O copy o elemento copí somente um nó atual sem as crianças e os atributos, quando cópia-das cópias tudo including as crianças e os atributos.
|
XML Source
<source>
<p id="a12"> Compare
<B>these constructs</B>.
</p>
</source>
|
Output
<DIV>
<B>copy-of : </B>
<p id="a12">
Compare <B>these constructs</B>.
</p>
</DIV>
<DIV>
<B>copy : </B>
<p/>
</DIV>
<DIV>
<B>value-of : </B>
Compare these constructs.
</DIV>
|
|
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="p">
<DIV>
<B>
<xsl:text>copy-of : </xsl:text>
</B>
<xsl:copy-of select="."/>
</DIV>
<DIV>
<B>
<xsl:text>copy : </xsl:text>
</B>
<xsl:copy/>
</DIV>
<DIV>
<B>
<xsl:text>value-of : </xsl:text>
</B>
<xsl:value-of select="."/>
</DIV>
</xsl:template>
</xsl:stylesheet>
|
|
Us-Atribu-Ajustam o atributo
|
Um xsl: o elemento da cópia pode ter us-atribu-ajustou o atributo. Nesta maneira os atributos para o elemento copí podem ser especificados. O stylesheet 2 de XSL não trabalha como esperado. Porque os expresions nos atributos que consultam aos objetos nomeados de XSL não são avaliados.
|
XML Source
<source>
<h1>GREETING</h1>
<p>Hello, world!</p>
</source>
|
Output
<h1 align="center" style="color:red">GREETING</h1>
<p align="left" style="color:blue">Hello, world!</p>
|
|
XSL stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<xsl:apply-templates select="/source/*"/>
</xsl:template>
<xsl:template match="h1">
<xsl:copy use-attribute-sets="H1">
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
<xsl:template match="p">
<xsl:copy use-attribute-sets="P ">
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
<xsl:attribute-set name="H1">
<xsl:attribute name="align">center</xsl:attribute>
<xsl:attribute name="style">color:red</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="P">
<xsl:attribute name="align">left</xsl:attribute>
<xsl:attribute name="style">color:blue</xsl:attribute>
</xsl:attribute-set>
</xsl:stylesheet>
|
|
XML Source
<source>
<h1>GREETING</h1>
<p>Hello, world!</p>
</source>
|
Output
Failed to compile stylesheet. 1 error detected.
javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected.
at com.icl.saxon.PreparedStyleSheet.prepare(PreparedStyleSheet.java:136)
at com.icl.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:127)
at Main$TransformerThread.transform(Main.java:105)
at Main$TransformerThread.run(Main.java:80)
at java.lang.Thread.run(Thread.java:536)
|
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<xsl:apply-templates select="/source/*"/>
</xsl:template>
<xsl:template match="*">
<xsl:copy use-attribute-sets="{name(.)}">
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
<xsl:attribute-set name="H1">
<xsl:attribute name="align">center</xsl:attribute>
<xsl:attribute name="style">color:red</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="P">
<xsl:attribute name="align">left</xsl:attribute>
<xsl:attribute name="style">color:blue</xsl:attribute>
</xsl:attribute-set>
</xsl:stylesheet>
|
|
|
|
Keywords Copy and Copy-of Constructs in XSL, xsl tutorial, xsl attributes, xsl examples,
xsl cdata, xsl reference, xsl example, xsl elements, xsl tags, xsl tutorials,
xsl functions, xsl attribute, xsl name, xsl syntax, xsl variable, w3schools xsl,
xsl dtd, xsl namespace, xsl count, xsl xpath, xsl javascript, xsl element,
xsl text, xsl document, xsl entity, xsl sort, xsl css, xsl doctype
|