![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
And xslt as follows: xsl:template match="/" h1>Hello World</h1 xsl:apply-templates select="/systems/system" /xsl:template xsl:template match="/systems/system" b><xsl:value-of select="administrator"></b /xsl:template If I transform the document directly by calling the XSLT file from within the XML document, I see: h1>Hello World</h1><b>John Doe</b However, if I use the XslCompiledTransform.Transform() method, I see: b>John Doe</b I guess this method is technically working correctly as it matches the pattern of the XML document, but it's a tad frustrating as I have code I need to drop in at the root of the document before that section gets transformed. Any ideas on a workaround? |
utput method="html"/>
#3
| |||
| |||
|
|
Kris wrote: And xslt as follows: xsl:template match="/" h1>Hello World</h1 xsl:apply-templates select="/systems/system" /xsl:template xsl:template match="/systems/system" b><xsl:value-of select="administrator"></b /xsl:template If I transform the document directly by calling the XSLT file from within the XML document, I see: h1>Hello World</h1><b>John Doe</b However, if I use the XslCompiledTransform.Transform() method, I see: b>John Doe</b I guess this method is technically working correctly as it matches the pattern of the XML document, but it's a tad frustrating as I have code I need to drop in at the root of the document before that section gets transformed. Any ideas on a workaround? Does it improve things when you use xsl:template match="/" h1>Hello World</h1 xsl:apply-templates select="systems/system" /xsl:template xsl:template match="systems/system" b><xsl:value-of select="administrator"></b /xsl:template ? Putting in a root element might also be a good idea e.g. assuming you want to create a snippet of HTML then a div container makes sense: xsl utput method="html"/xsl:template match="/" div h1>Hello World</h1 xsl:apply-templates select="systems/system" /div /xsl:template xsl:template match="systems/system" b><xsl:value-of select="administrator"></b /xsl:template -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ |
#4
| |||
| |||
|
|
Thanks for your help Martin, but I'm still seeing the same behavior. It seems as though the XSLT Transformation isn't picking up the root of the document. It picks up "systems/system" fine, but not "/" |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Private Function TransformData(ByVal data As XmlDocument, ByVal stylesheet As String) As String Dim xslCompiledTransform As New XslCompiledTransform Dim xPath As XPathNavigator = data.DocumentElement.CreateNavigator() Dim sb As New StringBuilder Dim sw As New StringWriter(sb) Dim xmlWriter As New XmlTextWriter(sw) xslCompiledTransform.Load(stylesheet) xslCompiledTransform.Transform(xPath, Nothing, xmlWriter) Return sb.ToString() End Function |
#7
| |||
| |||
|
|
Kris wrote: Private Function TransformData(ByVal data As XmlDocument, ByVal stylesheet As String) As String Dim xslCompiledTransform As New XslCompiledTransform Dim xPath As XPathNavigator = data.DocumentElement.CreateNavigator() Dim sb As New StringBuilder Dim sw As New StringWriter(sb) Dim xmlWriter As New XmlTextWriter(sw) xslCompiledTransform.Load(stylesheet) xslCompiledTransform.Transform(xPath, Nothing, xmlWriter) Return sb.ToString() End Function The problem is that you pass data.DocumentElement.CreateNavigator() to the Transform method, use data.CreateNavigator() instead and the stylesheet has a root node (/) to operate on. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |