I have a crawler service running on Windows (.NET Framework) to crawl different feeds and to create a new xml feeds. It was build about 10 years ago and hasn't been used for a while (about 2 years). If I try to run it now on a Windows Server 2012 R2 all goes well, with the exception of retrieving the values of "xsl:value-of". I'm trying to solve this (it used to run in the past). Who can tell me what I'm missing?
If I use static text it works. If I use xsl:call-template with xsl:with-param (see code below) is also retrieves the information. Only xsl:value-of is not retrieving values.
This is a part of the XML:
<?xml version="1.0" encoding="utf-8"?>
<products>
<product>
<productID>175436</productID>
<name>Best Stay Hotel</name>
<description><![CDATA[A nice place.]]></description>
<additional>
<field name="country">Cyprus</field>
</additional>
</product>
</products>
This is my XSLT (I've have removed some to make it shorter, include.xslt works as expected):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/products">
<xml>
<products>
<xsl:apply-templates select="product"/>
</products>
</xml>
</xsl:template>
<xsl:template match="product">
<product>
<xsl:attribute name="index">
<xsl:value-of select="position()"/>
</xsl:attribute>
<pprSubsiteID>
<xsl:value-of select="normalize-space(productID)" />
</pprSubsiteID>
<details>
<pprName>
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="normalize-space(name)" />
</xsl:call-template>
</pprName>
<pprCountry>
<xsl:value-of select="normalize-space(additional/field[@name='country'])"/>
</pprCountry>
<pprDescription>
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="normalize-space(description)" />
</xsl:call-template>
</pprDescription>
</details>
</product>
</xsl:template>
<xsl:template name="removeHtmlTags">
<xsl:param name="html"/>
<xsl:choose>
<xsl:when test="contains($html, '<')">
<xsl:value-of select="substring-before($html, '<')"/>
<!-- Recurse through HTML -->
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="substring-after($html, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$html"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
This is the what the output should look like:
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<products>
<product index="1">
<pprSubsiteID>175436</pprSubsiteID>
<details>
<pprName>Best Stay Hotel</pprName>
<pprCountry>Cyprus</pprCountry>
<pprDescription>A nice place.</pprDescription>
</details>
</product>
</products>
</xml>
This is the result I'm getting:
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<products>
<product index="1">
<pprSubsiteID></pprSubsiteID>
<details>
<pprName>Best Stay Hotel</pprName>
<pprCountry></pprCountry>
<pprDescription>A nice place.</pprDescription>
</details>
</product>
</products>
</xml>
So pprSubsiteID and pprCountry are missing.
Thanks for all your help!
xmlns="..."
on any of the elements? Thanks – Tim Cxmlns="..."
in your input XML, or there are none. Also, please fix the XSLT sample: For one thing, it's not correctly nested, a closing</details>
is missing. And for another thing, it contains references to code you don't show. Either include the definition of theremoveHtmlTags
template in your question, or remove any references to it from your XSLT. Code samples should be completely self-contained so people can actually copy & run them. – Tomalak