XSLT (XSL Transformations) Question:
Download Job Interview Questions and Answers PDF
How to transform an XML document into another XML document?
Answer:
Here,I given you a exampl which show you how to transform an XML document into another XML document.
Example:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/persons">
<root> <xsl:apply-templates select="person"/> </root>
</xsl:template>
<xsl:template match="person">
<name username="{@username}">
<xsl:value-of select="name" />
</name>
</xsl:template>
</xsl:stylesheet>
We can tranform above XML document into another document like that,
<?xml version="1.0" encoding="UTF-8"?>
<root>
<name username="jhoh">jhon</name>
<name username="smith">smith</name>
</root>
Example:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/persons">
<root> <xsl:apply-templates select="person"/> </root>
</xsl:template>
<xsl:template match="person">
<name username="{@username}">
<xsl:value-of select="name" />
</name>
</xsl:template>
</xsl:stylesheet>
We can tranform above XML document into another document like that,
<?xml version="1.0" encoding="UTF-8"?>
<root>
<name username="jhoh">jhon</name>
<name username="smith">smith</name>
</root>
Download XSLT Interview Questions And Answers
PDF
Previous Question | Next Question |
How to transform an XML into XHTML? | How we compare XSLT and XPath? |