I'm trying to do a basic XSLT transformation of the first <p>
tag into a <head>
tag. It works, but problem is that I use the <xsl:copy-of>
template for the other <p>
tag and it results in a <p part="N">
with this annoying @part
.
this is the XML tree :
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
schematypens="http://purl.oclc.org/dsdl/schematron"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>Title</title>
</titleStmt>
<publicationStmt>
<p>Publication Information</p>
</publicationStmt>
<sourceDesc>
<p>Information about the source</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<p>Title</p>
<p>Some text here.</p>
</body>
</text>
</TEI>
this is my XSL stylesheet :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="xs tei"
xmlns="http://www.tei-c.org/ns/1.0"
version="2.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no" encoding="UTF-8"/>
<xsl:template match="/TEI/teiHeader"/>
<xsl:template match="/TEI//body">
<div>
<head>
<xsl:value-of select="./p[1]"/>
</head>
<xsl:copy-of select="./p[2]"/>
</div>
</xsl:template>
</xsl:stylesheet>
and the result tree is :
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.tei-c.org/ns/1.0">
<head>Title</head>
<p part="N">Some text here.</p>
</div>
I find out that when I remove this statements in the input tree :
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
schematypens="http://purl.oclc.org/dsdl/schematron"?>
the @part
disappears from the output tree. Can you explain me why ? What are all of this xml-model
?
I'm using Oxygen XML Editor 24.1 and Saxon-EE 10.6 (same result with Saxon-PE 10.6 and Saxon-HE 10.6).
Thank you !
CodePudding user response:
The schema has
<define name="att.fragmentable.attribute.part">
<optional>
<attribute xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
name="part"
a:defaultValue="N">
<a:documentation>specifies whether or not its parent element is fragmented in some way, typically by some other overlapping structure: for example a speech which is divided between two or more verse stanzas, a paragraph which is split across a page division, a verse line which is divided between two speakers.</a:documentation>
<choice>
<value>Y</value>
<a:documentation>(yes) the element is fragmented in some (unspecified) respect</a:documentation>
<value>N</value>
<a:documentation>(no) the element is not fragmented, or no claim is made as to its completeness</a:documentation>
<value>I</value>
<a:documentation>(initial) this is the initial part of a fragmented element</a:documentation>
<value>M</value>
<a:documentation>(medial) this is a medial part of a fragmented element</a:documentation>
<value>F</value>
<a:documentation>(final) this is the final part of a fragmented element</a:documentation>
</choice>
</attribute>
</optional>
</define>
and p
elements reference that att.fragmentable.attribute.part
with i.e.
<define name="p">
<element name="p">
<a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0">(paragraph) marks paragraphs in prose. [3.1. Paragraphs 7.2.5. Speech Contents]</a:documentation>
<ref name="macro.paraContent"/>
<pattern xmlns="http://purl.oclc.org/dsdl/schematron"
id="tei_all-p-abstractModel-structure-p-in-ab-or-p-constraint-report-6">
<rule context="tei:p">
<sch:report xmlns="http://www.tei-c.org/ns/1.0"
xmlns:rng="http://relaxng.org/ns/structure/1.0"
xmlns:sch="http://purl.oclc.org/dsdl/schematron"
test="(ancestor::tei:ab or ancestor::tei:p) and not( ancestor::tei:floatingText |parent::tei:exemplum |parent::tei:item |parent::tei:note |parent::tei:q |parent::tei:quote |parent::tei:remarks |parent::tei:said |parent::tei:sp |parent::tei:stage |parent::tei:cell |parent::tei:figure )">
Abstract model violation: Paragraphs may not occur inside other paragraphs or ab elements.
</sch:report>
</rule>
</pattern>
<pattern xmlns="http://purl.oclc.org/dsdl/schematron"
id="tei_all-p-abstractModel-structure-p-in-l-or-lg-constraint-report-7">
<rule context="tei:p">
<sch:report xmlns="http://www.tei-c.org/ns/1.0"
xmlns:rng="http://relaxng.org/ns/structure/1.0"
xmlns:sch="http://purl.oclc.org/dsdl/schematron"
test="(ancestor::tei:l or ancestor::tei:lg) and not( ancestor::tei:floatingText |parent::tei:figure |parent::tei:note )">
Abstract model violation: Lines may not contain higher-level structural elements such as div, p, or ab, unless p is a child of figure or note, or is a descendant of floatingText.
</sch:report>
</rule>
</pattern>
<ref name="att.global.attributes"/>
<ref name="att.declaring.attributes"/>
<ref name="att.fragmentable.attributes"/>
<ref name="att.written.attributes"/>
<empty/>
</element>
</define>
So it is the RelaxNG schema that defines the attribute part
with the default value N
, the XSLT operates on the input tree with the default attribute values added and your <xsl:copy-of select="./p[2]"/>
copies that p
element with its attribute.
Depending on your needs you need to either disable the default attribute addition or you need to write XSLT to remove the part="N"
attribute e.g.
<xsl:template match="p/@part[. = 'N']"/>
and instead of <xsl:copy-of select="./p[2]"/>
use <xsl:apply-templates select="p[2]"/>
and declare/set up the identity transformation with e.g.
<xsl:mode on-no-match="shallow-copy"/>
CodePudding user response:
In the Oxygen Preferences->"XML / XML Parser / RELAX NG" page you can uncheck the "Add default attributes" checkbox.