0

Hi I just need to convert the DIta xml into xml file using XSLT:

My Input xml file is

<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>

But Output im getting as:

<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>

My Output need as like below

<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 We used:

<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>

Please look into this and provide me the correct code for transformation. Thanks in Advance

User515
  • 186
  • 12
  • The output you claim is not the output obtained using your code. Voting to close (again). – michael.hor257k Nov 21 '16 at 12:46
  • 1
    I am getting the same output as you but with a containing topic element which is not present in your output. Since the output you want is completely different from this, your code seems to be completely unrelated to the task you are trying to accomplish; in effect you are asking us to do the coding for you. StackOverflow is not a free coding service. – Michael Kay Nov 21 '16 at 15:21

0 Answers0