Connecting Tech Pros Worldwide Forums | Help | Site Map

Do ID & IDREF work in DOTNET - they do in MSXML4.0

VernonR
Guest
 
Posts: n/a
#1: Nov 12 '05
I'm having problems getting the .NET 1.1 XSL transform to cross reference
using ID / IDREF correctly. I have collapsed to a simple set of files to show
the problem more clearly...

The output line using MSXML4.0 is correct
<Output>First List Item = Hello</Output>

The output using MSXML3.0 or the DOTNET XSL transform is
<Output> = </Output>

Am I doing something wrong ?
Is there a workaround using the .NET 1.1 framework ?

I would prefer not to have to redistribute MSXML4.0 with the application
just to get round this particular problem..

Thanks...

The XML input file is
<?xml version="1.0" encoding="UTF-8"?>
<Document
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="c:\Snippet.xsd">
<ListItem ref="x1" />
<Description ref="x1" Title="First List Item" Value="Hello"></Description>
</Document>

The XSLT stylesheet is
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="">
<xsl:output method = "xml" indent="yes" encoding="utf-8" />
<xsl:template match="/">
<xsl:apply-templates select="Document"/>
</xsl:template>

<xsl:template match="Document">
<xsl:apply-templates select="ListItem"/>
</xsl:template>

<xsl:template match="ListItem">
<Output>
<xsl:value-of select="id(@ref)/@Title"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="id(@ref)/@Value"/>
</Output>
</xsl:template>

</xsl:stylesheet>

The schema file ( snippet.xsd ) is
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="Document">
<xs:complexType>
<xs:sequence>
<xs:element ref="ListItem"/>
<xs:element ref="Description"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="ListItem" type="ListItem"/>

<xs:complexType name="ListItem">
<xs:attribute name="ref" type="xs:IDREF"/>
</xs:complexType>

<xs:element name="Description" type="Description"/>

<xs:complexType name="Description">
<xs:sequence>
</xs:sequence>
<xs:attribute name="ref" type="xs:ID"/>
<xs:attribute name="Title" type="xs:string"/>
<xs:attribute name="Value" type="xs:string"/>
</xs:complexType>


</xs:schema>

The relevant code is :
Public Function Transform(ByVal sInputXMLFile As String, ByVal
sInputXSLTFile As String, ByVal sOutputFile As String)
Dim mNameTable As NameTable
Dim mNameSpaceMgr As XmlNamespaceManager
Dim mLang As String
Try
' Read the schema from disk
mKKXmlSchemaReader = New XmlTextReader("C:\snippet.xsd")

' first create a schema collection
mSchema = New XmlSchemaCollection
mSchema.Add(Nothing, mKKXmlSchemaReader)
mKKInputFile = New XmlTextReader(sInputXMLFile)
mKKValidInputFile = New XmlValidatingReader(mKKInputFile)
mKKValidInputFile.ValidationType = ValidationType.Schema
mKKValidInputFile.Schemas.Add(mSchema)
AddHandler mKKValidInputFile.ValidationEventHandler, AddressOf
ValidationCallBack
mKKXsltStage1 = New XmlTextReader(sInputXSLTFile)

doc1 = New XPathDocument(mKKValidInputFile)
' Transform the file.
Dim xslt As XslTransform = New XslTransform
xslt.Load(mKKXsltStage1, Nothing, Nothing)
mKKXmlTextWriter = New KKXmlTextWriter(sOutputFile, Nothing)
xslt.Transform(doc1, Nothing, mKKXmlTextWriter, Nothing)
mKKXmlTextWriter.Close()
mKKValidInputFile.Close()
mKKInputFile.Close()
Catch e2 As XmlException
Dim sMsg As String
sMsg = e2.Message
Catch e As InvalidCastException
Dim sMsg As String
sMsg = e.Message
End Try
End Function

Thanks in anticipation....

Oleg Tkachenko [MVP]
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Do ID & IDREF work in DOTNET - they do in MSXML4.0


VernonR wrote:
[color=blue]
> <Document
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="c:\Snippet.xsd">
> <ListItem ref="x1" />
> <Description ref="x1" Title="First List Item" Value="Hello"></Description>
> </Document>[/color]

..NET 1.X doesn't support id() function when for schema-defined IDs.
Actually XPath spec explicitly requires IDs to be defined in DTD. Take a
look at a workaround at http://www.tkachenko.com/blog/archives/000060.html

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com
VernonR
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Do ID & IDREF work in DOTNET - they do in MSXML4.0


Thanks. Your interesting workaround enables me to achieve what I want to...

Vernon

"Oleg Tkachenko [MVP]" wrote:
[color=blue]
> VernonR wrote:
>[color=green]
> > <Document
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xsi:noNamespaceSchemaLocation="c:\Snippet.xsd">
> > <ListItem ref="x1" />
> > <Description ref="x1" Title="First List Item" Value="Hello"></Description>
> > </Document>[/color]
>
> ..NET 1.X doesn't support id() function when for schema-defined IDs.
> Actually XPath spec explicitly requires IDs to be defined in DTD. Take a
> look at a workaround at http://www.tkachenko.com/blog/archives/000060.html
>
> --
> Oleg Tkachenko [XML MVP, MCAD]
> http://www.xmllab.net
> http://blog.tkachenko.com
>[/color]
Closed Thread