Transform XML Data for DDL

gotnetdude

Active member
Joined
Jan 24, 2008
Messages
27
Programming Experience
10+
I could use some help. I'm relatively new to XSL ... The problem I am having is getting the correct XML data to a dropdownlist control. I am unsure whether or not the following code works, because the output is the XSL, rather than the XML data. Ultimately I would like to transform the XML data into a bind able collection for the DDL. Ideally the rendered data will come from the transform directly through memory to the DDL control.

XML FILE:

VB.NET:
<?xml version="1.0" encoding="utf-8" ?> 
<Permissions xmlns:ns1="PermissionsMangement"> 
    <Permission> 
        <PermissionID>1</PermissionID> 
        <PermissionName>Chrysler</PermissionName> 
        <PermissionDescription>Chrysler Corporation</PermissionDescription> 
        <PermissionIsActive>1</PermissionIsActive> 
        <PermissionAddedDateTime>=01/01/2008 12:00:0000 PM</PermissionAddedDateTime> 
        <PermissionAddedBy>System</PermissionAddedBy> 
        <PermissionLastUpdatedBy>System</PermissionLastUpdatedBy> 
        <PermissionLastUpdatedBy>01/01/2008 12:00:0000 PM</PermissionLastUpdatedBy> 
    </Permission> 
    <Permission> 
        <PermissionID>2</PermissionID> 
        <PermissionName>Ford</PermissionName> 
        <PermissionDescription>Ford Corporation</PermissionDescription> 
        <PermissionIsActive>1</PermissionIsActive> 
        <PermissionAddedDateTime>=01/01/2008 12:00:0000 PM</PermissionAddedDateTime> 
        <PermissionAddedBy>System</PermissionAddedBy> 
        <PermissionLastUpdatedBy>System</PermissionLastUpdatedBy> 
        <PermissionLastUpdatedBy>01/01/2008 12:00:0000 PM</PermissionLastUpdatedBy> 
    </Permission> 
    <Permission> 
        <PermissionID>3</PermissionID> 
        <PermissionName>test</PermissionName> 
        <PermissionDescription>GM Corporation</PermissionDescription> 
        <PermissionIsActive>0</PermissionIsActive> 
        <PermissionAddedDateTime>01/01/2008 12:00:0000 PM</PermissionAddedDateTime> 
        <PermissionAddedBy>System</PermissionAddedBy> 
        <PermissionLastUpdatedBy>System</PermissionLastUpdatedBy> 
        <PermissionLastUpdatedBy>01/01/2008 12:00:0000 PM</PermissionLastUpdatedBy> 
    </Permission> 
    <Permission> 
        <PermissionID>4</PermissionID> 
        <PermissionName>GM</PermissionName> 
        <PermissionDescription>GM Corporation</PermissionDescription> 
        <PermissionIsActive>1</PermissionIsActive> 
        <PermissionAddedDateTime>01/01/2008 12:00:0000 PM</PermissionAddedDateTime> 
        <PermissionAddedBy>System</PermissionAddedBy> 
        <PermissionLastUpdatedBy>System</PermissionLastUpdatedBy> 
        <PermissionLastUpdatedBy>01/01/2008 12:00:0000 PM</PermissionLastUpdatedBy> 
     </Permission> 
</Permissions>

XSL:

VB.NET:
<?xml version="1.0" encoding="utf-8"?> 

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
     
    <xslutput method="xml"/> 

<xsl:template match="/"> 
     
    <Permissions> 
        <xsl:for-each order-by="+ PermissionName" select="Permission[PermissionName$gt$0]" 
            xmlns:xsl="http://www.w3.org/tr/wd-xsl"> 
            <Permission> 
                <PermissionName> 
                    <xsl:value-of select="PermissionName"></xsl:value-of> 
                </PermissionName> 
            </Permission> 
        </xsl:for-each> 
    </Permissions> 
     
    </xsl:template> 

</xsl:stylesheet>

XSD:

VB.NET:
<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="UserPermissionsXML" xmlns:ns1="PermissionsManagement" attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="Permissions"> 
        <xs:complexType> 
            <xs:sequence> 
                <xs:element maxOccurs="unbounded" name="Permission"> 
                    <xs:complexType> 
                        <xs:sequence> 
                            <xs:element name="PermissionID" type="xs:integer"> 
                            </xs:element> 
                            <xs:element name="PermissionName" type="xs:string"> 
                            </xs:element> 
                            <xs:element name="PermissionDescription" type="xs:string"> 
                            </xs:element> 
                            <xs:element name="PermissionIsActive" type="xs:integer"> 
                            </xs:element> 
                            <xs:element name="PermissionAddedDateTime" type="xs:string"> 
                            </xs:element> 
                            <xs:element name="PermissionAddedBy" type="xs:string"> 
                            </xs:element> 
                            <xs:element name="PermissionLastUpdatedBy" type="xs:string"> 
                            </xs:element> 
                            <xs:element name="PermissionLastUpdatedBy" type="xs:string"> 
                            </xs:element> 
                        </xs:sequence> 
                    </xs:complexType> 
                </xs:element> 
            </xs:sequence> 
        </xs:complexType> 
    </xs:element> 
</xs:schema>


Code behind:

VB.NET:
        Dim myXslTransform As XslCompiledTransform = New XslCompiledTransform() 

        myXslTransform.Load(HttpContext.Current.Server.MapPath("~/UserPermissionsXSLT.xsl")) 

        myXslTransform.Transform(HttpContext.Current.Server.MapPath("~/App_Data/UserPermissions.xml"), _ 
                                 HttpContext.Current.Server.MapPath("~/App_Data/UserPermissionsNew.xml")) 


        System.Diagnostics.Process.Start(HttpContext.Current.Server.MapPath("~/App_Data/UserPermissionsNew.xml"))
I'm using VS 2005. Thanks Paul
 
Back
Top