0
votes

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, '&lt;')">
            <xsl:value-of select="substring-before($html, '&lt;')"/>
            <!-- Recurse through HTML -->
            <xsl:call-template name="removeHtmlTags">
                <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
            </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!

1
Can you confirm you have shown is actually what is being used, as it should work as expected if that is the case? (See xsltfiddle.liberty-development.net/3NzcBuk). Are there actually any namespace declarations of the form xmlns="..." on any of the elements? ThanksTim C
I know... it used to work before and I don't understand why it's not working now. If tested it online with a tool myself and it does work. Can it be something with the server? I think before it was a Windows 2008 Server. Or the .NET Framework?5dale5
Can you answer the question Tim has asked?Tomalak
Not sure how to check. How/Where can I do that?5dale5
Either there are xmlns="..." 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 the removeHtmlTags 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

1 Answers

-1
votes
   <xsl:template match="products">
    <xml>
        <products>
            <product>
                <xsl:attribute name="index">
                    <xsl:value-of select="position()"/>
                </xsl:attribute>
                <pprSubsiteID><xsl:value-of select="//productID"/></pprSubsiteID>
                <details>
                    <pprName><xsl:value-of select="//name"/></pprName>
                    <pprCountry><xsl:value-of select="//additional/field"/></pprCountry>
                    <pprDescription><xsl:value-of select="//description"/></pprDescription>
                </details>
            </product>
        </products>
    </xml>
</xsl:template>