0

こんにちは、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 &amp; 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 &amp; Treatments</p>
      <p class="- topic/p " outputclass="MLU_Banner_Display">Yes</p>
      <p class="- topic/p " outputclass="MLU_Banner_Color">Medicines &amp; 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>

これを調べて、変換のための正しいコードを提供してください。前もって感謝します

4

0 に答える 0