Пока я конвертирую входной файл DITA в вывод XML, несколько одинаковых элементов, таких как <p class="- topic/p " outputclass="MLU_Intro">
, для одного родительского тега преобразуются в несколько одинаковых тегов.Использование XSLT для создания вывода DITA для XML. Один и тот же элемент попадает под дочерний элемент в родительский элемент.
Я новичок в XSLT, пожалуйста, всем, кто поможет мне решить вышеизложенную проблему.
Мой входной файл XML является:
<!DOCTYPE topic PUBLIC "urn:pubid:com.staywell.doctypes:doctypes:dita:topic" "topic.dtd">
<topic xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" xmlns:r="http://www.rsuitecms.com/rsuite/ns/metadata" class="- topic/topic " ditaarch:DITAArchVersion="1.2" domains="(topic hi-d) (topic indexing-d)(topic d4p_formatting-d)a(props d4p_renditionTarget)(topic d4p_math-d)(topic d4p_variables-d)(topic d4p_verse-d)(topic learningInteractionBase2-d learning2-d+learning-d)(topic learningBase+learningInteractionBase-d)(topic learningInteractionBase-d)(topic learningInteractionBase2-d)(topic xml-d)a(base rsuiteIdAtt)(topic sdClassification-d) " id="d43e3" outputclass="DOCTYPE-MLU" r:rsuiteId="6514" xml:lang="en-US">
<title class="- topic/title " outputclass="MLU">All About the A1C</title>
<body class="- topic/body ">
<p class="- topic/p " outputclass="MLU_Code">TP_02A</p>
<p class="- topic/p " outputclass="MLU_Type">Horizontal Click & Learn</p>
</body>
<topic class="- topic/topic " ditaarch:DITAArchVersion="1.2" domains="(topic hi-d) (topic indexing-d)(topic d4p_formatting-d)a(props d4p_renditionTarget)(topic d4p_math-d)(topic d4p_variables-d)(topic d4p_verse-d)(topic learningInteractionBase2-d learning2-d+learning-d)(topic learningBase+learningInteractionBase-d)(topic learningInteractionBase-d)(topic learningInteractionBase2-d)(topic xml-d)a(base rsuiteIdAtt)(topic sdClassification-d) " id="d43e15" outputclass="TOPIC-MLU-Header" r:rsuiteId="6515" xml:lang="en-US">
<title class="- topic/title " outputclass="MLU-Header">Header</title>
<body class="- topic/body ">
<p class="- topic/p " outputclass="MLU_Category">Management</p>
<p class="- topic/p " outputclass="MLU_Banner_Display">Yes</p>
**
<p class="- topic/p " outputclass="MLU_Intro">It’s great that.</p>
<p class="- topic/p " outputclass="MLU_Intro">
<ph class="- topic/ph " outputclass="Bold">Why the A1C</ph>
</p>
<p class="- topic/p " outputclass="MLU_Intro">An A1C test.</p>
<p class="- topic/p " outputclass="MLU_Intro">
<ph class="- topic/ph " outputclass="Bold">What to</ph>
<ph class="- topic/ph " outputclass="Bold">Results</ph>
</p>
<p class="- topic/p " outputclass="MLU_Intro">An A1C test result.</p>
**
<p class="- topic/p " outputclass="MLU_Directions">CLICK ON EACH ICON TO LEARN MORE.</p>
</body>
</topic>
</topic>
XSL, который я использовал:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" encoding="UTF-8" doctype-system="../DTDs/MLU.dtd" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="topic[@outputclass = 'DOCTYPE-MLU']">
<MLU>
<clickLearnHorizontal>
<xsl:apply-templates />
</clickLearnHorizontal>
</MLU>
</xsl:template>
<xsl:template match="topic[@outputclass = 'TOPIC-MLU-Header']">
<header>
<trackingSettings>
<urlcode>
<xsl:value-of select="//p[@outputclass = 'MLU_Code']" />
</urlcode>
<apiurl>http://mlucenter.com/like/api</apiurl>
</trackingSettings>
<page>
<xsl:value-of select="text()" />
</page>
<banner>
<enabled>true</enabled>
<text>
<xsl:value-of select="//title[@outputclass = 'MLU']" />
</text>
</banner>
<xsl:apply-templates />
</header>
</xsl:template>
<xsl:template match="body">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="p[@outputclass = 'MLU_Code']" />
<xsl:template match="title[@outputclass = 'MLU']" />
<xsl:template match="title[@outputclass = 'MLU-Header']" />
<xsl:template match="p[@outputclass = 'MLU_Condition']" />
<xsl:template match="p[@outputclass = 'MLU_Type']" />
<xsl:template match="p[@outputclass = 'MLU_Category']" />
<xsl:template match="p[@outputclass = 'MLU_Banner_Display']" />
<xsl:template match="p[@outputclass = 'MLU_Banner_Color']" />
<xsl:template match="p">
<introText>
<text>
<xsl:for-each select="p[@outputclass = 'MLU_Intro']">
<p>
<xsl:apply-templates />
</p>
</xsl:for-each>
</text>
</introText>
</xsl:template>
<!--<xsl:template match="p[@outputclass = 'MLU_Intro']"> </xsl:template>-->
<xsl:template match="p[@outputclass = 'MLU_Directions']">
<directionText>
<text>
<xsl:value-of select="//p[@outputclass = 'MLU_Directions']" />
</text>
</directionText>
</xsl:template>
<xsl:template match="title[@outputclass = 'MLU-Body']" />
<xsl:template match="title" />
<xsl:template match="ph">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="p[@outputclass = 'MLU_Item_Button']" />
<xsl:template match="p[@outputclass = 'MLU_Item_Title_Position']" />
<xsl:template match="bodydiv[@outputclass = 'Item_Defaults']" />
<xsl:template match="bodydiv">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="p">
<p>
<xsl:apply-templates />
</p>
</xsl:template>
<!--
<xsl:template match="p[@outputclass = 'MLU_Intro']">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
-->
<xsl:template match="image" />
<xsl:template match="@MLU_Banner_Display" />
<xsl:template match="@class">
<!--<xsl:apply-templates/>-->
</xsl:template>
<xsl:template match="ul">
<ul>
<xsl:apply-templates />
</ul>
</xsl:template>
<xsl:template match="ol">
<ol>
<xsl:apply-templates />
</ol>
</xsl:template>
<xsl:template match="li">
<li>
<xsl:apply-templates />
</li>
</xsl:template>
<xsl:template match="ph[@outputclass = 'Bold']">
<strong>
<xsl:apply-templates />
</strong>
</xsl:template>
</xsl:stylesheet>
Вывод XML, который я получил, как:
<!DOCTYPE MLU
SYSTEM "../DTDs/MLU.dtd">
<MLU>
<clickLearnHorizontal>
<header>
<trackingSettings>
<urlcode>TP_02A</urlcode>
<apiurl>http://mlucenter.com/like/api</apiurl>
</trackingSettings>
<page />
<banner>
<enabled>true</enabled>
<text>All About the A1C</text>
</banner>
**
<p>It’s great.</p>
<p>
<strong>Why the A1C</strong>
</p>
<p>An A1C test.</p>
<p>
<strong>What to Expect</strong>
<strong>Results</strong>
</p>
<p>An A1C test.</p>
**
<directionText>
<text>CLICK ON EACH ICON TO LEARN MORE.</text>
</directionText>
</header>
</clickLearnHorizontal>
</MLU>
Но я ожидал выход как:
<MLU>
<clickLearnHorizontal>
<header>
<trackingSettings>
<urlcode>TP_02A</urlcode>
<apiurl>http://mlucenter.com/like/api</apiurl>
</trackingSettings>
<page />
<banner>
<enabled>true</enabled>
<text>All About the A1C</text>
</banner>
**
<introText>
<text>
<p>It’s great.</p>
<p>
<strong>Why the A1C</strong>
</p>
<p>An A1C test.</p>
<p>
<strong>What to Expect</strong>
<strong>Results</strong>
</p>
<p>An A1C test.</p>
</text>
</introText>
**
<directionText>
<text>CLICK ON EACH ICON TO LEARN MORE.</text>
</directionText>
</header>
</clickLearnHorizontal>
</MLU>
Если вы получили приемлемый ответ, было бы вежливо принять его. – zx485