XSLT 2.0 zur Validierung des Ergebnisses der Transformation zu einem bestimmten XML-Schema ist ideal. Die DTD-Validierung wird nicht unterstützt.
Wenn Sie also ein XML-Schema für DITA finden (und es scheint some DITA schema vorhanden zu sein), können Sie es leicht überprüfen. Hier ist ein Beispiel, genommen von Michael Kay Buch „XSLT 2.0 und XPath 2.0“, wie die Validierung des Ergebnisses-Dokument auszuführen:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:import-schema namespace="http://www.w3.org/1999/xhtml"
schema-location="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd"/>
<xsl:output method="xhtml" indent="yes"/>
<xsl:template match="/">
<xsl:result-document validation="strict">
<html>
<head>
<title><xsl:value-of select="poem/title"/></title>
</head>
<body>
<h1 align="center"><xsl:value-of select="poem/title"/></h1>
<p align="center"><i>by </i><xsl:value-of select="poem/author/name"/>
(<xsl:value-of select="poem/author/(birth,death)" separator="-"/>)</p>
<xsl:for-each select="poem/stanza">
<p>
<xsl:for-each select="line">
<xsl:value-of select="."/>
<xsl:if test="position() != last()"><br/></xsl:if>
</xsl:for-each>
</p>
</xsl:for-each>
</body>
</html>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
wenn diese Transformation auf das folgende XML-Dokument angewendet wird:
<?xml version="1.0"?>
<poem xmlns="http://poetry.org/ns"
xsi:schemaLocation="http://poetry.org/ns poem.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<author>
<name>Rupert Brooke</name>
<birth>1887-08-03</birth>
<death>1915-04-23</death>
</author>
<date>1912</date>
<title>The Hill</title>
<stanza>
<line>Breathless, we flung us on the windy hill,</line>
<line>Laughed in the sun, and kissed the lovely grass.</line>
<line>You said "Through glory and ecstasy we pass;</line>
<line>Wind, sun, and earth remain, and birds sing still,</line>
<line>When we are old, are old...." "And when we die</line>
<line>All's over that is ours; and life burns on</line>
<line>Through other lovers, other lips" said I,</line>
<line>"Heart of my heart, our heaven is now, is won!"</line>
</stanza>
<stanza>
<line>We are Earth's best, that learnt her lesson here.</line>
<line>Life is our cry. We have kept the faith!" we said;</line>
<line>"We shall go down with unreluctant tread</line>
<line>Rose-crowned into the darkness!".... Proud we were,</line>
<line>And laughed, that had such brave true things to say.</line>
<line>-- And then you suddenly cried, and turned away.</line>
</stanza>
</poem>
der Saxon EE 9.2.1.2 Prozessor erzeugt die folgenden Fehlermeldungen:
SystemID: C:\Books\XSLT 2.0 and XPath 2.0\Downloads\Chapter4\ch04\poem-to-xhtml.xsl
Engine name: Saxon-EE 9.2.1.2
Severity: error
Description: Failed to compile stylesheet. 1 error detected.
SystemID: C:\Books\XSLT 2.0 and XPath 2.0\Downloads\Chapter4\ch04\poem-to-xhtml.xsl
Engine name: Saxon-EE 9.2.1.2
Severity: fatal
Description: Attribute align is not permitted in the content model of the complex type of element h1
Start location: 16:0
URL: http://www.w3.org/TR/xslt20/#err-XTTE1510
Hier finden Sie eine Zusammenfassung, wie Sie die XML-Schema-Validierung des Ergebnisdokuments erreichen:
.1. Importieren Sie mindestens ein Schema, zum Beispiel:
<xsl:import-schema namespace="http://www.w3.org/1999/xhtml"
schema-location="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd"/>
.2. Auf der <xsl:result-document>
Element geben Sie strenge Validierung, wie folgt ein:
<xsl:result-document validation="strict">
Gute Frage, +1. In meiner Antwort finden Sie ein Beispiel für die Schema-Validierung des Ergebnisses der XSLT 2.0-Umwandlung. –
Neben Dimitres Antwort über die Validierung von Ergebnisdokumenten, denke ich, dass dies eine Klarstellung erfordert: Eine Transformation ist eine Funktion von Eingabe zu Ausgabe. Die Ausgabe eines Ergebnistyps (zB DITA 1.1) oder eines anderen hängt davon ab, wie die Funktion definiert ist. Wenn die Funktion selbst keine Möglichkeit bietet, dies zu spezifizieren (durch Parameter), dann müssen Sie die Funktionsdefinition modifizieren (durch Erweiterung, Zusammensetzung, etc.). –
@Alejandro: Ja, Sie treffen genau das, was ich versuche zu tun . Ich versuche das DITA OT Plugin docbook2dita zu benutzen. Es wurde vor einigen Jahren geschrieben, d. vor DITA 1.2. und im TODO-Teil heißt es "Upgrade auf DITA 1.1 und DocBook 5". Was sollte ich für ein Upgrade auf dita 1.2 suchen? – Ace