0

I need some to help oon generating the XSL file for my XML Data.

Here is my XML Data

<?xml-stylesheet href="C:\Style.xsl" type="text/xsl" ?>    

<xml>
<ApproverRoles OperationType="RemovedUser" xmlns="http://tempuri.org/">
<UserName>Bhupathiraju, Venkata</UserName><UserRole>IT Owner</UserRole><RoleDescription>Role Owner
</RoleDescription><UserRoleID>138</UserRoleID></ApproverRoles>
<ApproverRoles OperationType="RemovedUser" xmlns="http://tempuri.org/">
<UserName>Bhupathiraju, Venkata</UserName><UserRole>Business Owner</UserRole>
<RoleDescription>Role Owner</RoleDescription><UserRoleID>136</UserRoleID></ApproverRoles>
<ApproverRoles OperationType="RemovedUser" xmlns="http://tempuri.org/"><UserName>Amperayeni, Kiran K</UserName>
<UserRole>IT Owner</UserRole><RoleDescription>asdasdasd</RoleDescription><UserRoleID>97</UserRoleID>
</ApproverRoles>
<ApproverRoles OperationType="RemovedUser" xmlns="http://tempuri.org/"><UserName>Amperayeni, Kiran K</UserName>
<UserRole>IT Owner</UserRole><RoleDescription>i</RoleDescription><UserRoleID>135</UserRoleID></ApproverRoles>
</xml>

My XSL file is below

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match ="/" >
        <html>
            <head>
                <title>User Management</title>
            </head>
            <body>
                <table width="600" border="1" style='font-family:Calibri;font-size:10pt;background-color:#FFFFFF;border-color:#ccccff'>
            <tr bgcolor = "#ccccff" style='font-weight:bold;'>
                <td colspan="3">Proposed Users :</td>
            </tr>
            <tr bgcolor = "#cccccc" style='font-weight:bold;'>
                <td>User Name</td>
                <td>Role</td>
                <td>Role Qualifier</td>
            </tr>

            <xsl:for-each select="//ns1:ApproverRoles" >
                <tr>
                    <td>
                        <xsl:value-of select="UserName" />
                    </td>
                    <td>
                        <xsl:value-of select="UserRole" />
                    </td>
                    <td>
                        <xsl:value-of select="RoleDescription" />
                    </td>
                </tr>
            </xsl:for-each>
            <tr bgcolor = "#ccccff" style='font-weight:bold;'>
                <td colspan="3">Removed Users :</td>
            </tr>
            <tr bgcolor = "#cccccc" style='font-weight:bold;'>
                <td>User Name</td>
                <td>Role</td>
                <td>Role Qualifier</td>
            </tr>
        </table>
            </body>
        </html>
    </xsl:template>


</xsl:stylesheet >
2
  • What is the desired output of your Xsl? Commented Jun 15, 2011 at 20:43
  • Just for information, entering the title of your question into Google gets 202,000 hits, many of which contain the answer to the question. Commented Jun 15, 2011 at 22:45

1 Answer 1

2

You are not correctly dealing with the default namespace present in the input document. If you do not associate a prefix to the corresponding namespace uri, the XSLT processor will search for elements in no namespace. Actually, the elements in your input document, are all in the namespace http://tempuri.org/.

So, you need first to declare the namespace prefix in the transform:

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ns1="http://tempuri.org/">

Then, you have to use the prefix accordingly. For instance:

                <xsl:for-each select="//ns1:ApproverRoles" >
                    <tr>
                        <td>
                            <xsl:value-of select="ns1:UserName" />
                        </td>
                        <td>
                            <xsl:value-of select="ns1:UserRole" />
                        </td>
                        <td>
                            <xsl:value-of select="ns1:RoleDescription" />
                        </td>
                    </tr>
                </xsl:for-each>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.