Groups | Blog | Home
all groups > dotnet xml > july 2004 >

dotnet xml : Using XSLT to Append Attributes to an XSD File


David Elliott
7/12/2004 2:23:52 PM
I wrote an application to scrape a database and create an XSD file which will be annotated
by a map file in order to create a Typed DataSet. I was wondering if I could do the annotation
using XSLT.

Here is background on Typed DataSet:
Using Annotations with a Typed DataSet
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconUsingAnnotationsWithTypedDataSet.asp

I need to append an attribute a specific XML node.

Change
<xs:element name="column_1" msdata:ReadOnly="true" minOccurs="0" type="xs:short" />
<xs:element name="column_2" msdata:ReadOnly="true" minOccurs="0" type="xs:int" />
to
<xs:element name="column_1" msdata:ReadOnly="true" minOccurs="0" type="xs:short" msprop:typedName="ID" />
<xs:element name="column_2" msdata:ReadOnly="true" minOccurs="0" type="xs:int" msprop:typedName="Name" />


I have included an XSD file that was returned as a result of my application before it is annotated.

Any thoughts would be appreciated.

Cheers,
Dave

=========================================================

<?xml version="1.0" standalone="yes"?>
<xs:schema id="DsStoredProc" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="DsStoredProc" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="column_1" msdata:ReadOnly="true" minOccurs="0" type="xs:short" />
<xs:element name="column_2" msdata:ReadOnly="true" minOccurs="0" type="xs:int" />
<xs:element name="column_3" msdata:ReadOnly="true" minOccurs="0" type="xs:int" />
<xs:element name="column_4" msdata:ReadOnly="true" minOccurs="0" type="xs:short" />
<xs:element name="column_5" msdata:ReadOnly="true" minOccurs="0" type="xs:int" />
<xs:element name="column_6" msdata:ReadOnly="true" minOccurs="0" type="xs:short" />
<xs:element name="column_7" msdata:ReadOnly="true" minOccurs="0" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="column_8" minOccurs="0" type="xs:short" />
<xs:element name="column_9" minOccurs="0" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table2">
<xs:complexType>
<xs:sequence>
<xs:element name="column_10" type="xs:int" />
<xs:element name="column_11" type="xs:short" />
<xs:element name="column_12" type="xs:int" />
<xs:element name="column_13" type="xs:short" />
<xs:element name="column_14" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
v-kevy NO[at]SPAM online.microsoft.com
7/13/2004 8:07:05 AM
Hi David,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to add annotation to your
typed dataset schema. If there is any misunderstanding, please feel free to
let me know.

As far as I know, the annotation is added to the .XSD files directly. So I
think we needn't use any programs to add them automatically. Although we
can use an XSLT to add, I think it will be more easier to add the
annotations manually to the schema.

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
David Elliott
7/13/2004 11:18:34 AM
Thanks.

Dave


[quoted text, click to view]
Oleg Tkachenko [MVP]
7/13/2004 2:47:46 PM
[quoted text, click to view]

That's piece of cake in XSLT, here is the idea:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msprop="msprop namespace">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xs:element[@name='column_1']">
<xsl:copy>
<xsl:attribute name="msprop:typedName">ID</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>


--
Oleg Tkachenko [XML MVP]
AddThis Social Bookmark Button