Link to home
Start Free TrialLog in
Avatar of rherguth
rherguthFlag for United States of America

asked on

Am I Insane? This XSLT is not finding my elements

I would expect the data "Schema" to show up in the transformed result.  Only "xml" does, so the XSLT is not properly identifying the Schema node when parsed.  This seems simple yet I cannot figure it out!

Simplified Source XML which is from a SQL Server SELECT FOR XML AUTO, XMLDATA command:
<?xml version="1.0" encoding="UTF-8"?>
<xml xmlns:sql="urn:schemas-microsoft-com:xml-sql">
      <Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
            <ElementType name="row" content="empty" model="closed">
                  <AttributeType name="HiddenActivityID" dt:type="i4"/>
                  <AttributeType name="HiddenAgreementID" dt:type="i4"/>
                  <AttributeType name="Contract_x0020_Group" dt:type="string"/>
                  <AttributeType name="Contractor" dt:type="string"/>
                  <AttributeType name="Project_x0020_Engineer" dt:type="string"/>
                  <AttributeType name="Project_x0020_Title" dt:type="string"/>
                  <AttributeType name="Task_x0020_Number" dt:type="string"/>
                  <AttributeType name="New_x0020_Mod_x0020_PR" dt:type="string"/>
                  <AttributeType name="Task_x0020_Name" dt:type="string"/>
                  <AttributeType name="Actions" dt:type="string"/>
                  <AttributeType name="Delete_x0020_Task" dt:type="string"/>
                  <AttributeType name="HiddenFY" dt:type="i4"/>
                  <AttributeType name="HiddenCETSerial" dt:type="string"/>
                  <attribute type="HiddenActivityID"/>
                  <attribute type="HiddenAgreementID"/>
                  <attribute type="Contract_x0020_Group"/>
                  <attribute type="Contractor"/>
                  <attribute type="Project_x0020_Engineer"/>
                  <attribute type="Project_x0020_Title"/>
                  <attribute type="Task_x0020_Number"/>
                  <attribute type="New_x0020_Mod_x0020_PR"/>
                  <attribute type="Task_x0020_Name"/>
                  <attribute type="Actions"/>
                  <attribute type="Delete_x0020_Task"/>
                  <attribute type="HiddenFY"/>
                  <attribute type="HiddenCETSerial"/>
            </ElementType>
      </Schema>
      <row xmlns="x-schema:#Schema1" HiddenActivityID="925" HiddenAgreementID="747" Contract_x0020_Group="Single Award" Contractor="XYZ" Project_x0020_Engineer="Joe TestGuy" Project_x0020_Title="Blah, Blah" Task_x0020_Number="ABC123" New_x0020_Mod_x0020_PR="New" Task_x0020_Name="Blah, Blah" Actions="View" Delete_x0020_Task="Delete" HiddenFY="2005" HiddenCETSerial="A1B"/>
      <row xmlns="x-schema:#Schema1" HiddenActivityID="924" HiddenAgreementID="745" Contract_x0020_Group="Single Award" Contractor="ABC" Project_x0020_Engineer="Joe TestGuy" Project_x0020_Title="Blah, Blah 2" Task_x0020_Number="ABC567" New_x0020_Mod_x0020_PR="New" Task_x0020_Name="Blah, Blah 2" Actions="View" Delete_x0020_Task="Delete" HiddenFY="2005" HiddenCETSerial="D1C"/>
      <row xmlns="x-schema:#Schema1" HiddenActivityID="923" HiddenAgreementID="744" Contract_x0020_Group="Other" Project_x0020_Engineer="Joe TestGuy" Project_x0020_Title="Blah, Blah 3" Task_x0020_Number="ABC789" New_x0020_Mod_x0020_PR="New" Task_x0020_Name="Blah, Blah 3" Actions="View" Delete_x0020_Task="Delete" HiddenFY="2005" HiddenCETSerial="K1D"/>
</xml>

Simplified XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
      <xsl:template match="/">
            <html>
                  <head/>
                  <body>
                        <xsl:for-each select="xml">
                              xml
                              <xsl:for-each select="Schema">
                                    Schema
                              </xsl:for-each>
                        </xsl:for-each>
                  </body>
            </html>
      </xsl:template>
</xsl:stylesheet>
Avatar of rherguth
rherguth
Flag of United States of America image

ASKER

Incidently, the result I get is:
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
                              xml
                              </body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of rdcpro
rdcpro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!  I figured that it was a namespace problem because that was all that was left, but I didn't really understand how they're used.  I had your site bookmarked already, so I probably had already found something useful there before.

I am creating an XSLT from one that I had created to gen tables from a saved XML ADO Stream, which formats the XML differently than MS SQL does.  I've found that the ADO XML Stream method of doings things is very slow compared to grabbing the ADO stream result directly from a MS SQL FOR XML AUTO, XMLDATA or EXPLICIT command.  So I'm nearly done now.  It was just this aspect that was holding me up for awhile.