5dale5
5dale5

Reputation: 13

why is "xsl:value-of" not working (anymore) and how can I resolve it?

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!

Upvotes: 0

Views: 385

Answers (1)

imran
imran

Reputation: 461

   <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>

Upvotes: -1

Related Questions