andrey.shedko
andrey.shedko

Reputation: 3238

Issue with XSLT attribute

I'm trying to do some transformation. So far everything look correct, but XSLT cannot get value one of the nodes (@Curl) meanwhile another node (@Name) value getting correct. Heres is XSLT:

<?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="/">
    <xsl:for-each select="Menu/Category">
      <h3>
        <i class="icon-cube"></i>
        <xsl:value-of select="MainCategory/@Name"/>
      </h3>
      <ul class="listview fluid">
        <xsl:for-each select="MainCategory/SubCategory">
          <li>
            <xsl:element name="a">
              <xsl:attribute name="href">
                <xsl:value-of select="@CUrl"/>
              </xsl:attribute>
              <xsl:value-of select="@Name"/>
            </xsl:element>
          </li>
        </xsl:for-each>
      </ul>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

And XML is here:

<?xml version="1.0" encoding="utf-8"?>
<Menu>
  <Category>
    <MainCategory Name="Транспорт"></MainCategory>
  </Category>
  <Category>
    <MainCategory Name="Недвижимость">
      <SubCategory CURL="http://shop.bubaport.ru/category/1" Name="Продажа"></SubCategory>
      <SubCategory CURL="http://shop.bubaport.ru/category/2" Name="Покупка"></SubCategory>
      <SubCategory CURL="http://shop.bubaport.ru/category/3" Name="Аренда"></SubCategory>
    </MainCategory>
  </Category>

Upvotes: 0

Views: 98

Answers (2)

Sripathi Acharya
Sripathi Acharya

Reputation: 83

XML is case sensitive. The attribute name mentioned in the XSL is not matching with the XML. Try with the below line.

<xsl:value-of select="@CURL"/>

Regards,

Upvotes: 0

nwellnhof
nwellnhof

Reputation: 33658

Attribute names are case-sensitive. In your XML, you have:

<SubCategory CURL="http://shop.bubaport.ru/category/1" Name="Продажа">

But in your XSL, you wrote:

<xsl:value-of select="@CUrl"/>

Try changing that to:

<xsl:value-of select="@CURL"/>

Upvotes: 3

Related Questions