How create XML from XML using XSL ?
I try like this.. but i not get a result
Test.xml
<Address>
<name> Alex</name>
<lastname>Mathew</lastname>
</Address>
Test.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Address>
<FirstName><xsl:value-of select="name" /></FirstName>
<LastName><xsl:value-of select="lastname" /></LastName>
</Address>
</xsl:template>
</xsl:stylesheet>
I need out put like this
<Address>
<FirstName> Alex</FirstName>
<LastName>Mathew</LastName>
</Address>
I try to convert in my asp page (test.asp)
<%
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("Test.xml"))
'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("Test.xsl"))
'Response.Write(xml.transformNode(xsl))
'Response.ContentType = "text/plain; charset=UTF-8"
Set doc = Server.CreateObject("Msxml2.DOMDocument.3.0")
doc.async = False
doc.loadXML(xml.transformNode(xsl))
response.write xml.transformNode(xsl)
response.write doc.getElementsByTagName("FirstName").item(0).text
%>
Plz help me solve this problem
Execute an XSLT transformation from an XML fileOpen an XML document in the XML editor. Associate an XSLT style sheet with the XML document. Add an xml-stylesheet processing instruction to the XML document. For example, add the following line to the document prolog: <?
XSLT is used to transform XML document from one form to another form. XSLT uses Xpath to perform matching of nodes to perform these transformation . The result of applying XSLT to XML document could be an another XML document, HTML, text or any another document from technology perspective.
The standard way to transform XML data into other formats is by Extensible Stylesheet Language Transformations (XSLT). You can use the built-in XSLTRANSFORM function to convert XML documents into HTML, plain text, or different XML schemas. XSLT uses stylesheets to convert XML into other data formats.
XSL (Extensible Stylesheet Language), formerly called Extensible Style Language, is a language for creating a style sheet that describes how data sent over the Web using the Extensible Markup Language (XML) is to be presented to the user.
XSL is a language that can transform XML into XHTML, a language that can filter and sort XML data, a language that can define parts of a XML document, a language that can format XML data based on the data value, like displaying negative numbers in red, and a language that can output XML data to different devices, like ...
You might also want to add an output directive in your stylesheet:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/Address">
<Address>
<FirstName><xsl:value-of select="name" /></FirstName>
<LastName><xsl:value-of select="lastname" /></LastName>
</Address>
</xsl:template>
</xsl:stylesheet>
This causes the output to have a leading xml declaration:
<?xml version="1.0" ?>
The problem is that "/"
is the root, not the root element (or "document element").
Hierarchically, "/"
is one level above the document element (<Address>
, in yor case). So this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/Address">
<Address>
<FirstName><xsl:value-of select="name" /></FirstName>
<LastName><xsl:value-of select="lastname" /></LastName>
</Address>
</xsl:template>
</xsl:stylesheet>
would actually work. Note the tiny little difference? Nicer would be this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- the identity template (copies your input verbatim) -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<!-- special templates only for things that need them -->
<xsl:template match="name">
<FirstName><xsl:value-of select="." /></FirstName>
</xsl:template>
<xsl:template match="lastname">
<LastName><xsl:value-of select="." /></LastName>
</xsl:template>
</xsl:stylesheet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With