Transforming XML with SelectSingleNode

Posted on 2006-05-18
Last Modified: 2013-11-19
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="" 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
Question by:lawso

    Author Comment

    Just to reiterate:
    If I find 'Latest' and '2'
    LVL 60

    Expert Comment

    by:Geert Bormans
    Hi lawso,
    > <xsl:stylesheet xmlns:xsl="" version="1.0">
    try this on the next line
    <xsl:output indent="yes" />

    LVL 60

    Expert Comment

    by:Geert Bormans

    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="" 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>

    Author Comment

    Gertone... The function is called from inside HTML so it has the HTML around it.
    I will give your other suggestion a try.
    LVL 60

    Accepted Solution

    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



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now