• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

Transforming XML with SelectSingleNode

Hi XMLers

I have some VB Script that processes some XML using XSLT.
I wanted to select just one node based on some request variables and then display that in HTML using XSLT.

I can select the correct node, but the XSLT simply draws out the values in one line.

Can someone help me .?

      <PORTFOLIO_NAME id="Latest">
            <PORTFOLIO_PAGE id="1">
            <PORTFOLIO_PAGE id="2">
      <PORTFOLIO_NAME id="Latest2">
            <PORTFOLIO_PAGE id="1">

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/PORTFOLIO_PAGE">

<xsl:for-each select="CLIENT">
      <xsl:value-of select="CLIENT_NAME"/>



xmlPath= "portfolio.xml"    'XML file path
      xslPath="transform.xslt"     'XSL file path

      Set xmlDoc = Server.CreateObject("msxml2.DOMDocument")
      Set xslDoc = Server.CreateObject("msxml2.DOMDocument")
      xmlDoc.async = False     'Allow the document to complete loading
      success = xmlDoc.Load(Server.MapPath(xmlPath))     'load the XML
      If (success) then     'file successfully loaded
            'set oNode = xmldoc.documentElement.SelectSingleNode("//PORTFOLIO_NAME[@id='Latest']").SelectSingleNode("PORTFOLIO_PAGE[@id=2]")
            'set oNode = xmldoc.SelectSingleNode("//PORTFOLIO_NAME[@id='Latest']/PORTFOLIO_PAGE[@id='1']")
            'Single Node with Params

            set oNode = xmldoc.SelectSingleNode("//PORTFOLIO_NAME[@id='Latest']/PORTFOLIO_PAGE[@id='1']")
            response.Write oNode.xml & "<hr>"
            xslDoc.async = False
            success = xslDoc.Load(Server.MapPath(xslPath))     'load the XSL
            If (success) then
                  Response.write oNode.transformNode(xslDoc)
                  Response.Write "Unable to load the stylesheet"
            End if
            Response.Write "Unable to load the XML source"
      End If

      Set xmlDoc = Nothing
      Set xslDoc = Nothing
  • 3
  • 2
1 Solution
lawsoAuthor Commented:
Just to reiterate:
If I find 'Latest' and '2'
Geert BormansCommented:
Hi lawso,
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
try this on the next line
<xsl:output indent="yes" />

Geert BormansCommented:

if you want this to be html,
then you need tags
your code has a > in front of it
new lines don't

> <?xml version="1.0" encoding="UTF-8" ?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> <xsl:template match="/PORTFOLIO_PAGE">
> <xsl:for-each select="CLIENT">
>      <xsl:value-of select="CLIENT_NAME"/>
> </xsl:for-each>
> </xsl:template>

> </xsl:stylesheet>
lawsoAuthor Commented:
Gertone... The function is called from inside HTML so it has the HTML around it.
I will give your other suggestion a try.
Geert BormansCommented:
well, it has the html around it,
but not in every repetion for CLIENT

If the entire stylesheet is called inside a <P> element,
then put a <BR /> in the repitition, like this

<xsl:for-each select="CLIENT">
   <xsl:value-of select="CLIENT_NAME"/> <BR />

if the stylesheet is called in a <body> element
keep my original example, without the html and body tags

<xsl:for-each select="CLIENT">
   <P><xsl:value-of select="CLIENT_NAME"/></P>

you will not get newlines in the browser because of newlines in the XML
you need paragraphs or <BR/> in the HTML

my other suggestion will work for XML tags only



Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now