您好我只需要使用XSLT将DIta xml转换为xml文件:
我的输入xml文件是
<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="d47e3" outputclass="DOCTYPE-MLU" r:rsuiteId="26396" xml:lang="en-US">
<title class="- topic/title " outputclass="MLU">Non-Insulin Injections: Up Close and
Personal</title>
<body class="- topic/body ">
<p class="- topic/p " outputclass="MLU_Code">W3333</p>
<p class="- topic/p " outputclass="MLU_Condition">Injections</p>
<p class="- topic/p " outputclass="MLU_Type">Select & Reflect</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="d47e13" outputclass="TOPIC-MLU-Header" r:rsuiteId="26397" xml:lang="en-US">
<title class="- topic/title " outputclass="MLU-Header">Header</title>
<body class="- topic/body ">
<p class="- topic/p " outputclass="MLU_Category">Medicines & Treatments</p>
<p class="- topic/p " outputclass="MLU_Banner_Display">Yes</p>
<p class="- topic/p " outputclass="MLU_Banner_Color">Medicines & Treatments</p>
<p class="- topic/p " outputclass="MLU_Intro">Several different non-insulin injections can be
prescribed.</p>
<p class="- topic/p " outputclass="MLU_Directions">SELECT THE NON-INSULIN INJECTION YOU'VE
BEEN PRESCRIBED FROM THE LIST OF GENERIC MEDICINES BELOW. IF YOU DON'T KNOW THE GENERIC NAME
OF YOUR MEDICINE, YOU CAN ALWAYS CHECK YOUR PRESCRIPTION LABEL.</p>
</body>
</topic>
</topic>
但输出即时为:
<banner>
<enabled>true</enabled>
<text>Non-Insulin Injections: Up Close and
Personal</text>
</banner>
<trackingSettings>
<urlcode>W3333</urlcode>
<apiurl>http://mlucenter.com/like/api</apiurl>
</trackingSettings>
<page/>
<header>
<introText><text>Several different non-insulin injections can be
prescribed.</text>
</introText>
<directionText><text>SELECT THE NON-INSULIN INJECTION YOU'VE
BEEN PRESCRIBED FROM THE LIST OF GENERIC MEDICINES BELOW. IF YOU DON'T KNOW THE GENERIC NAME
OF YOUR MEDICINE, YOU CAN ALWAYS CHECK YOUR PRESCRIPTION LABEL.</text></directionText>
</header>
我的输出需要如下所示
<header>
<trackingSettings>
<urlcode>W3333</urlcode>
<apiurl>http://mlucenter.com/like/api</apiurl>
</trackingSettings>
<page></page>
<banner>
<enabled>true</enabled>
<text>Non-Insulin Injections: Up Close and Personal</text>
</banner>
<introText>
<text>Several different non-insulin injections can be prescribed.</text>
</introText>
<directionText>
<text>SELECT THE NON-INSULIN INJECTION YOU'VE BEEN PRESCRIBED FROM THE LIST OF GENERIC
MEDICINES BELOW. IF YOU DON'T KNOW THE GENERIC NAME OF YOUR MEDICINE, YOU CAN ALWAYS CHECK
YOUR PRESCRIPTION LABEL.</text>
</directionText>
</header>
XSL我们用过:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="topic[@outputclass='TOPIC-MLU-Header']">
<header>
<xsl:apply-templates/>
</header>
</xsl:template>
<xsl:template match="body">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="p[@outputclass='MLU_Code']">
<trackingSettings>
<urlcode>
<xsl:value-of select="//p[@outputclass='MLU_Code']"/>
</urlcode>
<apiurl>http://mlucenter.com/like/api</apiurl>
</trackingSettings>
<page></page>
</xsl:template>
<xsl:template match="title[@outputclass='MLU']">
<banner>
<enabled>true</enabled>
<text>
<xsl:apply-templates/>
</text></banner>
</xsl:template>
<xsl:template match="title[@outputclass='MLU-Header']">
</xsl:template>
<xsl:template match="p[@outputclass='MLU_Condition']">
</xsl:template>
<xsl:template match="p[@outputclass='MLU_Type']">
</xsl:template>
<xsl:template match="p[@outputclass='MLU_Category']">
</xsl:template>
<xsl:template match="p[@outputclass='MLU_Banner_Display']">
</xsl:template>
<xsl:template match="p[@outputclass='MLU_Banner_Color']">
</xsl:template>
<xsl:template match="p[@outputclass='MLU_Intro']">
<introText>
<text>
<xsl:value-of select="//p[@outputclass='MLU_Intro']"/>
</text></introText>
</xsl:template>
<xsl:template match="p[@outputclass='MLU_Directions']">
<directionText>
<text>
<xsl:value-of select="//p[@outputclass='MLU_Directions']"/>
</text></directionText>
</xsl:template>
请仔细研究并提供正确的转换代码。在此先感谢