0

I am using the following code to transform my XML. But it's not reproducing results.

My XML:

<items>
  <Books>
    <Book ItemId="BK000023">
      <Name>Book Name 1</Name>
      <Group GroupID="BG3434344" HomeGroupInd="1">
        <Name>Home Group</Name>
      </Group>
    </Book>
    <Book ItemId="BK000024">
      <Name>Book Name 1</Name>
      <Group GroupID="BG343555" HomeGroupInd="2">
        <Name>Home Group</Name>
      </Group>
    </Book>
  </Books>
</items>

My XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes" encoding="UTF-8"/>
    <xsl:template match="/">
        <MyList>
        <xsl:for-each select="items/Books/Book">
            <Item>
                <xsl:attribute name="ID">W<xsl:value-of select="@WorkAreaID"/>
                </xsl:attribute>
                <xsl:attribute name="Tag">W</xsl:attribute>
                <xsl:attribute name="Thumb">11</xsl:attribute>
                <xsl:attribute name="Pic">24</xsl:attribute>
                <Text>
                    <xsl:value-of select="Name"/>
                </Text>
            </Item>
        </xsl:for-each>
        </MyList>
    </xsl:template>
</xsl:stylesheet>

My Classic ASP code:

<%
    Dim objXML
    Dim objXSL
    Dim strXMLFileName
    Dim strXSLFile
    Dim strHtml

    strXMLFileName=Server.MapPath("test.xml")   
    strXSLFile=Server.MapPath("eyb.xsl")

    set objXML = Server.CreateObject("Microsoft.XMLDOM")
    objXML.async = false
    objXML.load(strXMLFile)

    set objXSL = Server.CreateObject("Microsoft.XMLDOM")
    objXSL.async = false
    objXSL.load(strXSLFile)

    strHtml = objXML.transformNode(objXSL)
    Response.Write( server.HTMLEncode( strHtml))

    set objXML = nothing
    set objXSL = nothing
%>

My Result is always like <MyList></MyList> XSL is not looping the XML nodes. If I use the same XML and XSL in any online sites or any tools to transform the XML then it's giving expected results. What am I doing wrong here?

blue
  • 833
  • 2
  • 12
  • 39
  • The usual reason why XPath/XSLT doesn't work is namespaces, so any chance your XML has any `...` declaration? – Martin Honnen May 15 '20 at 19:06
  • no namespaces, it's exactly same as I have listed in my question. – blue May 15 '20 at 19:11
  • 4
    I would start debugging by checking the result of the `load` calls. Do you get true there, indicating the XML and XSLT were successfully loaded and parsed? And what kind of system is that? Which MSXML version is installed? I would use `Msxml2.DOMDocument.3.0` or `Msxml2.DOMDocument.6.0` instead to use any of the supported MSXML versions. – Martin Honnen May 15 '20 at 19:15
  • 3
    Thanks when I debugged the code then I found there was an error in parsing. Once I fixed that then it started working. – blue May 15 '20 at 19:46
  • Is it possible to load xml string instead of XML file? – blue May 15 '20 at 20:32
  • 1
    Yes, sure, use `loadXML` instead of `load`, but start reading some tutorial on MSXML and/or API doc before firing up more questions in comments to this question. – Martin Honnen May 15 '20 at 20:38
  • @Lankymart - the OP is asking how to do xsl transformations with classic asp - which he should really have made more clear in the title of the question – John May 18 '20 at 09:49
  • Does this answer your question? [Parsing XML with ASP](https://stackoverflow.com/a/20412236) – user692942 May 18 '20 at 09:55
  • @John either way it's a duplicate and not likely to help anyone else stumbling across it. They are not the first person on the site to try transforming XML in Classic ASP but not bother to check for parse errors. – user692942 May 18 '20 at 09:56

0 Answers0