• Ask a Question
  • Create a Poll
150
    Ask a Question
    Cancel
    150
    More answer You can create 5 answer(s).
      Ask a Poll
      Cancel

      Error When Getting Attribute Value of an XML Node

      I am trying to get value of an attribute but getting error

      <GetListResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">   <GetListResult>     <List RootFolder="/something/FileUploadTest">     </List>   </GetListResult> </GetListResponse> 

      XSLT

      <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:sp="http://schemas.microsoft.com/sharepoint/soap/" version="1.0"> <xsl:template match="/" name="ShowVariables"> <xsl:copy-of select="/sp:GetListResponse/sp:GetListResult/sp:List/@RootFolder"/> </xsl:template> </xsl:stylesheet> 

      I am getting this error

      The execution returned an unexpected error. An item of type ‘Attribute’ cannot be constructed within a node of type ‘Root’.

      Asked by Barretthaleloise on July 16, 2020 in XML.
      1 Answers

      You cannot create an attribute on its own. It cannot exist on its own. It should be a parent element first. Attributes exist in the context of elements only.

      The XSLT below creates a bogus literal element <fafa>. Jut after that we can create a copy of the attribute.

      XSLT #1

      <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://schemas.microsoft.com/sharepoint/soap/" exclude-result-prefixes="a">     <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>      <xsl:template match="/" name="ShowVariables">         <fafa>             <!--<xsl:copy-of select="/a:GetListResponse/a:GetListResult/a:List/@RootFolder"/>-->             <xsl:value-of select="a:GetListResponse/a:GetListResult/a:List/@RootFolder"/>         </fafa>     </xsl:template> </xsl:stylesheet> 

      Output

      <fafa>/something/FileUploadTest</fafa> 

      XSLT #2

      <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://schemas.microsoft.com/sharepoint/soap/" exclude-result-prefixes="a">     <xsl:output method="text" />      <xsl:template match="/" name="ShowVariables">             <xsl:value-of select="a:GetListResponse/a:GetListResult/a:List/@RootFolder"/>     </xsl:template> </xsl:stylesheet> 

      Output

      /something/FileUploadTest 
      Answered by Earlegrovershelley on July 16, 2020..