I am trying to create an XSLT file, and I can get it to work without including the namespace in either file, but as soon as I do include in either, it stops working.
here are the examples I’m using.
My XML file
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Empire sdf</title>
<artist>Bob sdf</artist>
<country>2</country>
<company>asdfs</company>
<price>12.90</price>
<year>1935</year>
</cd>
</catalog>
My Transform file.
<?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="/">
<html><body><table border="1">
<tr bgcolor="#9acd32"><th>Title</th><th>Artist</th></tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table></body></html>
</xsl:template>
</xsl:stylesheet>
My Results
<?xml version="1.0" encoding="UTF-8"?>
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td>Empire Burlesque</td>
<td>Bob Dylan</td>
</tr>
<tr>
<td>Empire sdf</td>
<td>Bob sdf</td>
</tr>
</table>
</body>
</html>
No if I alter the above to this.
My New XML file
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog
xmlns="http://www.someurl.com/v3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.someurl.com/v3.0 ../someschema.xsl"
>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Empire sdf</title>
<artist>Bob sdf</artist>
<country>2</country>
<company>asdfs</company>
<price>12.90</price>
<year>1935</year>
</cd>
</catalog>
My New Transform file.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.someurl.com/v3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.someurl.com/v3.0 ../someschema.xsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<html><body><table border="1">
<tr bgcolor="#9acd32"><th>Title</th><th>Artist</th></tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table></body></html>
</xsl:template>
</xsl:stylesheet>
I now get no data out in my transformed file?
Please excuse if this question is basic, I have no experience with XSLT and I’m trying to wrap my head around it currently.
In XSLT 2.0 : you just have to add in your
xsl:stylesheetelement the following attribute :xpath-default-namespace="http://www.someurl.com/v3.0".With XSLT 1.0 : you have to qualify your namespaces in the xsl file by giving a prefix. Example below :