Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Extract single node from XML using XSLT

$
0
0

I have the following code with a small snippet of XML. How can I use XSLT to extract a single node from the XML:

Option Explicit
Const strXSLT As String = "<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">" _& "<xsl:output indent=""yes""/><xsl:template match=""*""><xsl:copy>" _& "<xsl:copy-of select=""/Root/Item1""/>" _& "</xsl:copy></xsl:template></xsl:stylesheet>"
Const strXML As String = "<Root><Item1>A</Item1><Item2>B</Item2></Root>"
Sub Test()
Dim oXMLDoc As Object
Dim oXSLT As Object
Dim strXML As String
  Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
  Set oXSLT = CreateObject("MSXML2.DOMDocument")
  oXMLDoc.LoadXML strXML
  oXSLT.LoadXML strXSLT
  strXML = oXMLDoc.transformNode(oXSLT)
  Debug.Print strXML
End Sub

My desired output would be:

<Item1>A</Item1>

Thanks.



Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>