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