I want to display my xml file in datagrid but there is a problem while displaying inside of <annPubDate> tag because it has 2 sub elements <annTime> and <annDate>. I want to display these elements. Please help me !!
This is my xml file:
< xml version="1.0" encoding="iso-8859-9" > <annPanel> <ann> <annID /> <annTitle /> <annBody /> <annPubDate> <annDate /> <annTime /> </annPubDate> <annPriority /> <annSender /> </ann> <ann> <annID>1</annID> <annTitle>asdas</annTitle> <annBody>asd</annBody> <annPubDate> <annDate>11 / 8 / 2006</annDate> <annTime>11:48:5</annTime> </annPubDate> <annPriority /> <annSender /> </ann> <ann> <annID>2</annID> <annTitle>asdas</annTitle> <annBody>asd</annBody> <annPubDate> ---> This Part <annDate>11 / 8 / 2006</annDate> <annTime>11:48:8</annTime> </annPubDate> ---> End of <annPubDate> <annPriority /> <annSender /> </ann> In this xml file i want to display the <annDate> and <annTime> in seperate coloumns in datagrid view by using xsl schemaAnd This is my XSL file:
< xml version="1.0" > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> <xsl:strip-space elements="*"/> <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" standalone="yes" /> <xsl:template match="/"> <xsl:for-each select="annPanel"> <xsl:element name="annPanel"> <xsl:for-each select="ann"> <xsl:element name="ann"> <xsl:attribute name="annID"> <xsl:value-of select="annID"/> </xsl:attribute> <xsl:attribute name="annTitle"> <xsl:value-of select="annTitle"/> </xsl:attribute> <xsl:attribute name="annBody"> <xsl:value-of select="annBody"/> </xsl:attribute> <xsl:for-each select="annPubDate"> --->I think the problem is here but i dont know what is it... <xsl:element name="annPubDate"> <xsl:attribute name="annDate"> <xsl:value-of select="annDate"></xsl:value-of> </xsl:attribute> <xsl:attribute name="annTime"> <xsl:value-of select="annTime"></xsl:value-of> </xsl:attribute> </xsl:element> </xsl:for-each> ---> End <xsl:attribute name="annPriority"> <xsl:value-of select="annPriority"/> </xsl:attribute> <xsl:attribute name="annSender"> <xsl:value-of select="annSender"/> </xsl:attribute> </xsl:element> </xsl:for-each> </xsl:element> </xsl:for-each> </xsl:template> </xsl:stylesheet>
Problem in Displaying XML file using XSL Schema please help
sjb31988
Can you help me with my XSLT I am getting the same exception:
<
xml version="1.0" encoding="UTF-8" ><
xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><
xsl:output method="xml" /><
xsl:template match="/"><
Messages><
xsl:apply-templates select="//Messages/Message/Output/HighLevelCommand" /></
Messages></
xsl:template><
xsl:template match="HighLevelCommand"><
Message MessageID="1"><
Input><
CommandType><
xsl:value-of select="//Messages/Message/Input/Key/@CommandType" /></
CommandType><
ControlObject PriorityCode="7"><
xsl:apply-templates select="//Messages/Message/Input/Key" /><
xsl:apply-templates select="./LowLevelCommands/Hardware/LowLevelCommand" /><
xsl:apply-templates select="./Parameters/Parameter" /></
ControlObject></
Input><
Output /><
Exceptions /></
Message></
xsl:template><
xsl:template match="Key"><
xsl:attribute name="ID"><xsl:value-of select="./@ID"/></xsl:attribute><
xsl:attribute name="ObjectType"><xsl:value-of select="./@ObjectType"/></xsl:attribute></
xsl:template><
xsl:template match="LowLevelCommand"><
xsl:attribute name="RepeatFrequency"><xsl:value-of select="./@RepeatPeriod" /></xsl:attribute><
xsl:variable name="intHardwareType" select="../@HardwareType" /><
xsl:variable name="intLowestDenominatorObjectType" select="./@LowestDenominatorObjectType" /><
xsl:if test="//Messages/Message/Output/Hardware[@HardwareType=$intHardwareType and @LowestDenominatorObjectType=$intLowestDenominatorObjectType][position() > 0]" ><
HardwareDetail><
xsl:attribute name="HardwareType"><xsl:value-of select="../@HardwareType"/></xsl:attribute><
xsl:attribute name="FunctionCode"><xsl:value-of select="./@FunctionCode"/></xsl:attribute><
xsl:attribute name="CommandFormat"><xsl:value-of select="./@FormattingString"/></xsl:attribute><
xsl:attribute name="MaxResponseSize"><xsl:value-of select="./@MaxResponseSize"/></xsl:attribute><
xsl:attribute name="LowestDenominatorObjectType"><
xsl:value-of select="./@LowestDenominatorObjectType"/></
xsl:attribute><
xsl:apply-templates select="./@ParameterID" /><
xsl:choose><
xsl:when test="./@CanObjectRepeat = 'False'"><
xsl:apply-templates select="//Messages/Message/Output/Hardware[@HardwareType=$intHardwareType and @LowestDenominatorObjectType=$intLowestDenominatorObjectType]/Processor/*"><
xsl:with-param name="CanObjectRepeat" select="'False'" /></
xsl:apply-templates></
xsl:when><
xsl:when test="./@CanObjectRepeat = 'True'"><
xsl:apply-templates select="//Messages/Message/Output/Hardware[@HardwareType=$intHardwareType and @LowestDenominatorObjectType=$intLowestDenominatorObjectType]/Processor" /></
xsl:when></
xsl:choose></
HardwareDetail></
xsl:if></
xsl:template><
xsl:template match="@ParameterID"><
xsl:attribute name="ParameterID"><xsl:value-of select="." /></xsl:attribute><
xsl:attribute name="ParameterValue"><xsl:value-of select="../@ParameterValue" /></xsl:attribute></
xsl:template><
xsl:template match="Processor"><
Address><
xsl:attribute name="ProcessorID"><xsl:value-of select="./@ID" /></xsl:attribute><
xsl:choose><
xsl:when test="./@IPAddress != ''"><
xsl:choose><
xsl:when test="./@UIPort != ''"><
xsl:attribute name="IPAddress"><xsl:value-of select="concat(concat(./@IPAddress,':'),./@UIPort)" /></xsl:attribute></
xsl:when><
xsl:otherwise><
xsl:attribute name="IPAddress"><xsl:value-of select="./@IPAddress" /></xsl:attribute></
xsl:otherwise></
xsl:choose></
xsl:when><
xsl:otherwise><
xsl:choose><
xsl:when test="./@FutureUIPort != ''"><
xsl:attribute name="IPAddress"><xsl:value-of select="concat(concat(./@FutureIPAddress,':'),./@FutureUIPort)" /></xsl:attribute></
xsl:when><
xsl:otherwise><
xsl:attribute name="IPAddress"><xsl:value-of select="./@FutureIPAddress" /></xsl:attribute></
xsl:otherwise></
xsl:choose></
xsl:otherwise></
xsl:choose><
xsl:attribute name="SystemID"><xsl:value-of select="./@SystemID" /></xsl:attribute><
xsl:apply-templates select="./*"><
xsl:with-param name="CanObjectRepeat" select="'True'" /></
xsl:apply-templates></
Address></
xsl:template><
xsl:template match="Processor/*"><
xsl:param name="CanObjectRepeat" select="'True'"/><
xsl:choose><
xsl:when test = "../../@LowestDenominatorObjectType = '1660'"><
xsl:choose><
xsl:when test="$CanObjectRepeat = 'False'"><
Address><
xsl:attribute name="ProcessorID"><xsl:value-of select="../@ID" /></xsl:attribute><
xsl:choose><
xsl:when test="../@IPAddress != ''"><
xsl:choose><
xsl:when test="../@UIPort != ''"><
xsl:attribute name="IPAddress"><xsl:value-of select="concat(concat(../@IPAddress,':'),../@UIPort)" /></xsl:attribute></
xsl:when><
xsl:otherwise><
xsl:attribute name="IPAddress"><xsl:value-of select="../@IPAddress" /></xsl:attribute></
xsl:otherwise></
xsl:choose></
xsl:when><
xsl:otherwise><
xsl:choose><
xsl:when test="../@FutureUIPort != ''"><
xsl:attribute name="IPAddress"><xsl:value-of select="concat(concat(../@FutureIPAddress,':'),../@FutureUIPort)" /></xsl:attribute></
xsl:when><
xsl:otherwise><
xsl:attribute name="IPAddress"><xsl:value-of select="../@FutureIPAddress" /></xsl:attribute></
xsl:otherwise></
xsl:choose></
xsl:otherwise></
xsl:choose><
xsl:attribute name="SystemID"><xsl:value-of select="../@SystemID" /></xsl:attribute><
Object><
xsl:attribute name="ObjectType"><xsl:value-of select="../../@LowestDenominatorObjectType" /></xsl:attribute><
xsl:attribute name="ObjectOrder"><xsl:value-of select="0" /></xsl:attribute><
xsl:attribute name="SystemAddress"></xsl:attribute></
Object></
Address></
xsl:when><
xsl:when test="$CanObjectRepeat = 'True'"><
Object><
xsl:attribute name="ObjectType"><xsl:value-of select="../../@LowestDenominatorObjectType" /></xsl:attribute><
xsl:attribute name="ObjectOrder"><xsl:value-of select="position()-1" /></xsl:attribute><
xsl:attribute name="SystemAddress"></xsl:attribute></
Object></
xsl:when></
xsl:choose></
xsl:when><
xsl:otherwise><
xsl:choose><
xsl:when test="$CanObjectRepeat = 'False'"><
Address><
xsl:attribute name="ProcessorID"><xsl:value-of select="../@ID" /></xsl:attribute><
xsl:choose><
xsl:when test="../@IPAddress != ''"><
xsl:choose><
xsl:when test="../@UIPort != ''"><
xsl:attribute name="IPAddress"><xsl:value-of select="concat(concat(../@IPAddress,':'),../@UIPort)" /></xsl:attribute></
xsl:when><
xsl:otherwise><
xsl:attribute name="IPAddress"><xsl:value-of select="../@IPAddress" /></xsl:attribute></
xsl:otherwise></
xsl:choose></
xsl:when><
xsl:otherwise><
xsl:choose><
xsl:when test="../@FutureUIPort != ''"><
xsl:attribute name="IPAddress"><xsl:value-of select="concat(concat(../@FutureIPAddress,':'),../@FutureUIPort)" /></xsl:attribute></
xsl:when><
xsl:otherwise><
xsl:attribute name="IPAddress"><xsl:value-of select="../@FutureIPAddress" /></xsl:attribute></
xsl:otherwise></
xsl:choose></
xsl:otherwise></
xsl:choose><
xsl:attribute name="SystemID"><xsl:value-of select="../@SystemID" /></xsl:attribute><
Object><
xsl:attribute name="ObjectType"><xsl:value-of select="./@ObjectType" /></xsl:attribute><
xsl:attribute name="ObjectOrder"><xsl:value-of select="0" /></xsl:attribute><
xsl:attribute name="SystemAddress"><xsl:value-of select="./@SystemAddress" /></xsl:attribute></
Object></
Address></
xsl:when><
xsl:when test="$CanObjectRepeat = 'True'"><
Object><
xsl:attribute name="ObjectType"><xsl:value-of select="./@ObjectType" /></xsl:attribute><
xsl:attribute name="ObjectOrder"><xsl:value-of select="position()-1" /></xsl:attribute><
xsl:attribute name="SystemAddress"><xsl:value-of select="./@SystemAddress" /></xsl:attribute></
Object></
xsl:when></
xsl:choose></
xsl:otherwise></
xsl:choose></
xsl:template><
xsl:template match="Parameter"><
Parameter><
xsl:attribute name="ParameterID"><xsl:value-of select="./@ParameterID" /></xsl:attribute><
xsl:attribute name="ParameterOrder">0</xsl:attribute><
xsl:value-of select="./@DefaultValue" /><
xsl:value-of select="./@ParameterValue" /></
Parameter></
xsl:template></
xsl:stylesheet>Muhammad Akhtar Shiekh
I expect by "xsl schema" you meen "xsl stylesheet".
How your xsl relates to datagrid What's wrong with your xsl in particular or what you want to achive with it
Enes Kabacaoglu
The error XslCompiledTransform gives is: "Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added."
This is because you Stylesheet adds attribute "annPriority" after an element "annPubDate".
To fix the error you should move attribute creation before element creation.