Xml 需要使用标题关闭topic元素
我有四个标题名为h1、h2、h3和h4,我希望每个标题都需要根据DTD采用不同的样式 XML输入为:Xml 需要使用标题关闭topic元素,xml,xslt,Xml,Xslt,我有四个标题名为h1、h2、h3和h4,我希望每个标题都需要根据DTD采用不同的样式 XML输入为: <Segments> <Segment> <Body> <h1>Introduction:</h1> <h2>Introductory Paragraph</h2> <p>The introductory paragraph should also include the thesis stateme
<Segments>
<Segment>
<Body>
<h1>Introduction:</h1>
<h2>Introductory Paragraph</h2>
<p>The introductory paragraph should also include the thesis statement</p>
<h3>Body — First paragraph:</h3>
<p>The first paragraph of the body should contain the strongest argument</p>
<h4>Conclusion:</h4>
<p>an allusion to the pattern used in the introductory paragraph</p>
<h4>Concluding paragraph:</h4>
<p>On the days you get treatment</p>
</Body>
</Segment>
</Segments>
导言:
介绍段
导言部分还应包括论文陈述
正文-第一段:
正文的第一段应该包含最有力的论点
结论:
对介绍性段落中使用的模式的暗示
结论段:
在你接受治疗的日子里
XSL I用作:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="#all">
<xsl:output
method="xml"
indent="yes"
omit-xml-declaration="no"
doctype-public="urn:pubid:com.doctypes.doctypes:doctypes:dita:topic"
doctype-system="topic.dtd"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:processing-instruction name="xml-stylesheet">type="text/xsl" href="DITA.xsl"</xsl:processing-instruction>
<xsl:apply-templates select="//Body"/>
</xsl:template>
<xsl:template match="Segments">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Segment">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Body">
<xsl:for-each-group select="*" group-starting-with="h1">
<topic>
<xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4"/></xsl:attribute>
<title>
<xsl:apply-templates select="node()"/>
</title>
<xsl:for-each-group select="current-group() except ." group-starting-with="h2">
<subsection>
<xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4"/></xsl:attribute>
<title>
<xsl:apply-templates select="node()"/>
</title>
<body><xsl:apply-templates select="current-group() except ."/></body>
<xsl:for-each-group select="current-group() except ." group-starting-with="h3">
<subsection>
<xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4"/></xsl:attribute>
<title>
<xsl:apply-templates select="node()"/>
</title>
<body><xsl:apply-templates select="current-group() except ."/></body>
<xsl:for-each-group select="current-group() except ." group-starting-with="h4">
<subsection>
<xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4"/></xsl:attribute>
<title>
<xsl:apply-templates select="node()"/>
</title>
<body><xsl:apply-templates select="current-group() except ."/></body>
</subsection>
</xsl:for-each-group>
</subsection>
</xsl:for-each-group>
</subsection>
</xsl:for-each-group>
</topic>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
type=“text/xsl”href=“DITA.xsl”
话题_
话题_
话题_
话题_
我得到的输出是:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="DITA.xsl"?>
<!DOCTYPE topic
PUBLIC "urn:pubid:com.doctypes.doctypes:doctypes:dita:topic" "topic.dtd">
<topic id="topic_1">
<title>Introduction:</title>
<subsection id="topic_2">
<title>Introductory Paragraph</title>
<body>
<p>The introductory paragraph should also include the thesis statement</p>
<h3>Body — First paragraph:</h3>
<p>The first paragraph of the body should contain the strongest argument</p>
<h4>Conclusion:</h4>
<p>an allusion to the pattern used in the introductory paragraph</p>
<h4>Concluding paragraph:</h4>
<p>On the days you get treatment</p>
</body>
<subsection id="topic_">
<title>The introductory paragraph should also include the thesis statement</title>
<body/>
</subsection>
<subsection id="topic_3">
<title>Body — First paragraph:</title>
<body>
<p>The first paragraph of the body should contain the strongest argument</p>
<h4>Conclusion:</h4>
<p>an allusion to the pattern used in the introductory paragraph</p>
<h4>Concluding paragraph:</h4>
<p>On the days you get treatment</p>
</body>
<subsection id="topic_">
<title>The first paragraph of the body should contain the strongest argument</title>
<body/>
</subsection>
<subsection id="topic_4">
<title>Conclusion:</title>
<body>
<p>an allusion to the pattern used in the introductory paragraph</p>
</body>
</subsection>
<subsection id="topic_5">
<title>Concluding paragraph:</title>
<body>
<p>On the days you get treatment</p>
</body>
</subsection>
</subsection>
</subsection>
</topic>
导言:
介绍段
导言部分还应包括论文陈述
正文-第一段:
正文的第一段应该包含最有力的论点
结论:
对介绍性段落中使用的模式的暗示
结论段:
在你接受治疗的日子里
导言部分还应包括论文陈述
正文-第一段:
正文的第一段应该包含最有力的论点
结论:
对介绍性段落中使用的模式的暗示
结论段:
在你接受治疗的日子里
正文的第一段应该包含最有力的论点
结论:
对介绍性段落中使用的模式的暗示
结论段:
在你接受治疗的日子里
我希望输出为:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="DITA.xsl"?>
<!DOCTYPE topic
PUBLIC "urn:pubid:com.doctypes.doctypes:doctypes:dita:topic" "topic.dtd">
<topic id="topic_1">
<title>Introduction:</title>
<subsection id="topic_2">
<title>Introductory Paragraph</title>
<body>
<p>The introductory paragraph should also include the thesis statement</p>
</body>
<subsection id="topic_3">
<title>Body — First paragraph:</title>
<body>
<p>The first paragraph of the body should contain the strongest argument</p>
</body>
<subsection id="topic_4">
<title>Conclusion:</title>
<body>
<p>an allusion to the pattern used in the introductory paragraph</p>
</body>
</subsection>
<subsection id="topic_5">
<title>Concluding paragraph:</title>
<body>
<p>On the days you get treatment</p>
</body>
</subsection>
</subsection>
</subsection>
</topic>
导言:
介绍段
导言部分还应包括论文陈述
正文-第一段:
正文的第一段应该包含最有力的论点
结论:
对介绍性段落中使用的模式的暗示
结论段:
在你接受治疗的日子里
请在这方面指导我。提前感谢您可以为每个组重写用于检查第一项是否为标题的
:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="#all">
<xsl:output
method="xml"
indent="yes"
omit-xml-declaration="no"
doctype-public="urn:pubid:com.doctypes.doctypes:doctypes:dita:topic"
doctype-system="topic.dtd"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:processing-instruction name="xml-stylesheet">type="text/xsl" href="DITA.xsl"</xsl:processing-instruction>
<xsl:apply-templates select="//Body"/>
</xsl:template>
<xsl:template match="Body">
<xsl:for-each-group select="*" group-starting-with="h1">
<topic>
<xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4"/></xsl:attribute>
<title>
<xsl:apply-templates select="node()"/>
</title>
<xsl:for-each-group select="current-group() except ." group-starting-with="h2">
<subsection>
<xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4"/></xsl:attribute>
<title>
<xsl:apply-templates select="node()"/>
</title>
<xsl:for-each-group select="current-group() except ." group-starting-with="h3">
<xsl:choose>
<xsl:when test="self::h3">
<subsection>
<xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4"/></xsl:attribute>
<title>
<xsl:apply-templates select="node()"/>
</title>
<xsl:for-each-group select="current-group() except ." group-starting-with="h4">
<xsl:choose>
<xsl:when test="self::h4">
<subsection>
<xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4"/></xsl:attribute>
<title>
<xsl:apply-templates select="node()"/>
</title>
<body><xsl:apply-templates select="current-group() except ."/></body>
</subsection>
</xsl:when>
<xsl:otherwise>
<body><xsl:apply-templates select="current-group()"/></body>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</subsection>
</xsl:when>
<xsl:otherwise>
<body><xsl:apply-templates select="current-group()"/></body>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</subsection>
</xsl:for-each-group>
</topic>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
type=“text/xsl”href=“DITA.xsl”
话题_
话题_
话题_
话题_
在线