XSL. Please, need help. Thank You.

S

shapper

Hello,

I created a XSL file to convert a XML file to another XML.
I am running this in Asp.Net but this is not working.

----- ORIGINAL XML -----

<?xml version="1.0" encoding="utf-8" ?>
<siteMap
xmlns="http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode
url="~/Contacts.aspx"
title="Contacts"
description="Contacts Description"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="0.4"
google="true" />
<siteMapNode
url="~/Message.aspx"
title="Message"
description="Message Description"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="0.2"
google="false" />
</siteMapNode>
</siteMap>

----- What XML result should be (Domain Parameter =
"http://www.domain.com") -----

<?xml version="1.0" encoding="UTF-8"?>
< urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
< url>
< loc>http://www.mydomain.com/Contacts.aspx</loc>
< changefreq>daily</changefreq>
< lastmod>2006-11-01T20:25:42+01:00</lastmod>
< priority>0.4</priority>
</url>
</urlset>

----- XSL -----

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:dk="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<xsl:eek:utput method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:param name="Domain"/>
<xsl:template match="dk:*"/>
<xsl:template match="@*|text()|comment()"/>
<xsl:template match="/">
<xsl:element name="urlset">
<xsl:apply-templates select="//dk:siteMapNode[@google='true']"/>
</xsl:element>
</xsl:template>
<xsl:template match="dk:siteMapNode">
<xsl:element name="url">
<xsl:element name="loc">
<xsl:value-of select="$Domain" />
<xsl:value-of select="substring(@url, 3)"/>
</xsl:element>
<xsl:element name="lastmod">
<xsl:value-of select="@lastmod"/>
</xsl:element>
<xsl:element name="changefreq">
<xsl:value-of select="@changefreq"/>
</xsl:element>
<xsl:element name="priority">
<xsl:value-of select="@priority"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

Could someone, please, tell me why is this not working?

And is there a software or web site where I can test a XSL conversion?

Thanks,
Miguel
 
D

Dimitre Novatchev

The namespace in your stylesheet with prefix "dk" is bound to a
namespace-uri, which is not the namespace-uri for any namespace in the xml
document.

Compare the two:

xmlns="http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" (from the
xml document)

and

xmlns:dk="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" (from
the stylesheet)


It is wellknown fact that string comparisons in XPath are case-sensitive.



This is why the Xpath expression:

//dk:siteMapNode[@google='true']


selects nothing.


To rectify the problem correct the namespace uri.


Cheers,
Dimitre Novatchev


shapper said:
Hello,

I created a XSL file to convert a XML file to another XML.
I am running this in Asp.Net but this is not working.

----- ORIGINAL XML -----

<?xml version="1.0" encoding="utf-8" ?>
<siteMap
xmlns="http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode
url="~/Contacts.aspx"
title="Contacts"
description="Contacts Description"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="0.4"
google="true" />
<siteMapNode
url="~/Message.aspx"
title="Message"
description="Message Description"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="0.2"
google="false" />
</siteMapNode>
</siteMap>

----- What XML result should be (Domain Parameter =
"http://www.domain.com") -----

<?xml version="1.0" encoding="UTF-8"?>
< urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
< url>
< loc>http://www.mydomain.com/Contacts.aspx</loc>
< changefreq>daily</changefreq>
< lastmod>2006-11-01T20:25:42+01:00</lastmod>
< priority>0.4</priority>
</url>
</urlset>

----- XSL -----

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:dk="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<xsl:eek:utput method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:param name="Domain"/>
<xsl:template match="dk:*"/>
<xsl:template match="@*|text()|comment()"/>
<xsl:template match="/">
<xsl:element name="urlset">
<xsl:apply-templates select="//dk:siteMapNode[@google='true']"/>
</xsl:element>
</xsl:template>
<xsl:template match="dk:siteMapNode">
<xsl:element name="url">
<xsl:element name="loc">
<xsl:value-of select="$Domain" />
<xsl:value-of select="substring(@url, 3)"/>
</xsl:element>
<xsl:element name="lastmod">
<xsl:value-of select="@lastmod"/>
</xsl:element>
<xsl:element name="changefreq">
<xsl:value-of select="@changefreq"/>
</xsl:element>
<xsl:element name="priority">
<xsl:value-of select="@priority"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

Could someone, please, tell me why is this not working?

And is there a software or web site where I can test a XSL conversion?

Thanks,
Miguel
 
S

shapper

Hi Dimitre,

Thank You Very Much.
I was around my VB.NET and XSL code all week and I was getting
desperate.
I could not understand why my code was not working.

Sorry, for the cross posting.
I just didn't know in which should I post because I had no idea where
my problem was.
XML, XSL or even VB.NET where I also posted a message.

Thank You Once Again!
Miguel

Dimitre said:
The namespace in your stylesheet with prefix "dk" is bound to a
namespace-uri, which is not the namespace-uri for any namespace in the xml
document.

Compare the two:

xmlns="http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" (from the
xml document)

and

xmlns:dk="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" (from
the stylesheet)


It is wellknown fact that string comparisons in XPath are case-sensitive.



This is why the Xpath expression:

//dk:siteMapNode[@google='true']


selects nothing.


To rectify the problem correct the namespace uri.


Cheers,
Dimitre Novatchev


shapper said:
Hello,

I created a XSL file to convert a XML file to another XML.
I am running this in Asp.Net but this is not working.

----- ORIGINAL XML -----

<?xml version="1.0" encoding="utf-8" ?>
<siteMap
xmlns="http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode
url="~/Contacts.aspx"
title="Contacts"
description="Contacts Description"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="0.4"
google="true" />
<siteMapNode
url="~/Message.aspx"
title="Message"
description="Message Description"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="0.2"
google="false" />
</siteMapNode>
</siteMap>

----- What XML result should be (Domain Parameter =
"http://www.domain.com") -----

<?xml version="1.0" encoding="UTF-8"?>
< urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
< url>
< loc>http://www.mydomain.com/Contacts.aspx</loc>
< changefreq>daily</changefreq>
< lastmod>2006-11-01T20:25:42+01:00</lastmod>
< priority>0.4</priority>
</url>
</urlset>

----- XSL -----

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:dk="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<xsl:eek:utput method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:param name="Domain"/>
<xsl:template match="dk:*"/>
<xsl:template match="@*|text()|comment()"/>
<xsl:template match="/">
<xsl:element name="urlset">
<xsl:apply-templates select="//dk:siteMapNode[@google='true']"/>
</xsl:element>
</xsl:template>
<xsl:template match="dk:siteMapNode">
<xsl:element name="url">
<xsl:element name="loc">
<xsl:value-of select="$Domain" />
<xsl:value-of select="substring(@url, 3)"/>
</xsl:element>
<xsl:element name="lastmod">
<xsl:value-of select="@lastmod"/>
</xsl:element>
<xsl:element name="changefreq">
<xsl:value-of select="@changefreq"/>
</xsl:element>
<xsl:element name="priority">
<xsl:value-of select="@priority"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

Could someone, please, tell me why is this not working?

And is there a software or web site where I can test a XSL conversion?

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top