[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: DTD/Schemas with repeated structure

  • From: johns@s... (John F. Schlesinger)
  • To: 'John F Schlesinger' <Johns@s...>, tpassin@h...,"'Xml-Dev (E-mail 2)'" <xml-dev@l...>
  • Date: Fri, 25 Aug 2000 15:00:29 -0400

xsl value of disable
Here's a version of the style sheet that works with the MSXML3 style sheet
processor (I've also attached it to allow for line breaks). All I did was
put the output with the &gt; and &lt; inside <xsl:text> elements. The output
looks fine even if you don't disable output escaping...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='text'/>
<xsl:template match="/things">
	<xsl:apply-templates/>
</xsl:template>
<xsl:template match='thing'>
	<xsl:variable name='name' select='text()'/>
	<xsl:text disable-output-escaping="yes">&lt;!ELEMENT </xsl:text>
	<xsl:value-of select='$name'/> (<xsl:value-of select='$name'/>Name,
<xsl:value-of select='$name'/><xsl:text
disable-output-escaping="yes">Type)&gt;
&lt;!ATTLIST </xsl:text><xsl:value-of disable-output-escaping='yes'
select='$name'/><xsl:text disable-output-escaping="yes">Name (latin|common)
"common"&gt;
&lt;!ELEMENT </xsl:text><xsl:value-of select='$name'/><xsl:text
disable-output-escaping="yes">Type (#PCDATA)&gt;
</xsl:text>
</xsl:template>
</xsl:stylesheet>

The output I get is:

<!ELEMENT Mammal (MammalName,  MammalType)>
<!ATTLIST MammalName (latin|common) "common">
<!ELEMENT MammalType (#PCDATA)>
<!ELEMENT Fish (FishName,  FishType)>
<!ATTLIST FishName (latin|common) "common">
<!ELEMENT FishType (#PCDATA)>
<!ELEMENT Bird (BirdName,  BirdType)>
<!ATTLIST BirdName (latin|common) "common">
<!ELEMENT BirdType (#PCDATA)>

Yours,
John F Schlesinger
SysCore Solutions
212 619 5200 x 219
917 886 5895 Mobile

-----Original Message-----
From: John F Schlesinger [mailto:Johns@s...]
Sent: Friday, August 25, 2000 1:08 PM
To: 'tpassin@h...'; 'Xml-Dev (E-mail 2)'
Subject: RE: DTD/Schemas with repeated structure


Tom,
I tried your stylesheet and got a message (from the 'conforming' MS parser)
"Attribute 'disable-output-escaping' is invalid on 'xsl:output'."

So I looked up the specification at http://www.w3.org/TR/xslt and found:

"An xsl:value-of or xsl:text element may have a disable-output-escaping
attribute; the allowed values are yes or no; the default is no; if the value
is yes, then a text node generated by instantiating the xsl:value-of or
xsl:text element should be output without any escaping."

The specification for xsl:output doesn't mention the disable-output-escaping
attribute. Am I doing something wrong?

Yours,
John F Schlesinger
SysCore Solutions
212 619 5200 x 219
917 886 5895 Mobile

-----Original Message-----
From: tpassin@h... [mailto:tpassin@h...]
Sent: Thursday, August 24, 2000 7:16 PM
To: Xml-Dev (E-mail 2)
Subject: Re: DTD/Schemas with repeated structure


Justin Lipton asked about generating a simple, repetitive DTD structure
automagically (see his post at the end).

Simple - stick with xml and use an xslt stylesheet!.  It's about as easy as
programming it, possibly easier.  Of course, you do have to create the xml
file...

Here's the input xml file:

<things>
 <thing>Mammal</thing>
 <thing>Fish</thing>
 <thing>Bird</thing>
</things>

Here's the stylesheet (the mailer will break the lines at awkward places so
I am also attaching it):

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='text' disable-output-escaping='yes'/>
 <xsl:template match="/things"><xsl:apply-templates/></xsl:template>

 <xsl:template match='thing'>
<xsl:variable name='name' select='text()'/>
&lt;!ELEMENT <xsl:value-of select='$name'/> (<xsl:value-of
select='$name'/>Name, <xsl:value-of select='$name'/>Type)&gt;
&lt;!ATTLIST <xsl:value-of select='$name'/>Name (latin|common) "common"&gt;
&lt;!ELEMENT <xsl:value-of select='$name'/>Type (#PCDATA)&gt;
 </xsl:template>

</xsl:stylesheet>

Here's the output, just what you asked for:

D:>xt things.xml things.xsl


<!ELEMENT Mammal (MammalName, MammalType)>
<!ATTLIST MammalName (latin|common) "common">
<!ELEMENT MammalType (#PCDATA)>


<!ELEMENT Fish (FishName, FishType)>
<!ATTLIST FishName (latin|common) "common">
<!ELEMENT FishType (#PCDATA)>


<!ELEMENT Bird (BirdName, BirdType)>
<!ATTLIST BirdName (latin|common) "common">
<!ELEMENT BirdType (#PCDATA)>

Cheers,

Tom Passin


==============================================================
> I was wondering if anyone has come across this problem.
> We are currently using a DTD that has the following structure.
> Ignore the actual names used here as they are purely for illustrative
> purposes but assume that there is no choice but to use such a structure:
>
> <!ELEMENT Mammal (MammalName, MammalType)>
> <!ELEMENT MammalName (#PCDATA)>
> <!ATTLIST MammalName (latin|common) "common">
> <!ELEMENT MammalType (#PCDATA)>
>
> <!ELEMENT Fish (FishName, FishType)>
> <!ATTLIST FishName (latin|common) "common">
> <!ELEMENT FishType (#PCDATA)>
>
> <!ELEMENT Bird (BirdName, BirdType)>
> <!ATTLIST BirdName (latin|common) "common">
> <!ELEMENT BirdType (#PCDATA)>
>
> Image dozens of elements like this!
>
> Is there a way (either with a Schema or a DTD) to generalise this type of
> structure such that:
> <!ELEMENT * (*Name, *Type)>
> <!ATTLIST *Name (latin|common) "common">
> <!ELEMENT *Type (#PCDATA)>
>

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='text'/>
<xsl:template match="/things">
	<xsl:apply-templates/>
</xsl:template>
<xsl:template match='thing'>
	<xsl:variable name='name' select='text()'/>
	<xsl:text disable-output-escaping="yes">&lt;!ELEMENT </xsl:text>
	<xsl:value-of select='$name'/> (<xsl:value-of select='$name'/>Name,  <xsl:value-of select='$name'/><xsl:text disable-output-escaping="yes">Type)&gt;
&lt;!ATTLIST </xsl:text><xsl:value-of disable-output-escaping='yes' select='$name'/><xsl:text disable-output-escaping="yes">Name (latin|common) "common"&gt;
&lt;!ELEMENT </xsl:text><xsl:value-of select='$name'/><xsl:text disable-output-escaping="yes">Type (#PCDATA)&gt;
</xsl:text> 
</xsl:template>
</xsl:stylesheet>

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.