0
votes

Since last week I am googling, reading through all relevant Stackoverflow answers/topics regarding this topic (from other sources as well), but haven't still figured out a solution.

I have following XML:

    ?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
    <process id="10" name="Process 1" ownerOE="OE1" accountableOE="accounttableOE1" lastUpdate="" delete="aktiv">
         <description>
            <![CDATA[Some description 1]]>
         </description>              
         <App name="App1" ic-id="100" />
    </process>
    
    <process id="20" name="Process 2" ownerOE="OE2" accountableOE="accounttableOE2" lastUpdate="" delete="aktiv">
         <description>
            <![CDATA[Some description 2]]>
         </description>              
         <App name="App1" ic-id="100" />
    </process>
</root>

Following the XSLT which I've written:

   <?xml version='1.0' ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
        <xsl:template match="/">
        <ImportSchemaBase>
                <xsl:for-each select="root/process">
                    <Process>
                        <Title>
                            <xsl:value-of select="@name"/>
                        </Title>
                         <Description>
                            <xsl:value-of select="@description"/>
                        </Description>
                        <Tech_ID>
                            <xsl:value-of select="@id"/>
                        </Tech_ID>
                        <lastUpdate>
                            <xsl:value-of select="@lastUpdate"/>
                        </lastUpdate>
                        <deleteFlag>
                            <xsl:value-of select="@delete"/>
                        </deleteFlag>
                    </Process>
                </xsl:for-each>
        </ImportSchemaBase>
        </xsl:template>
</xsl:stylesheet>

The current output:

<ImportSchemaBase>
   <Process>
      <Title>Process 1</Title>
      <Description/>
      <Tech_ID>10</Tech_ID>
      <lastUpdate/>
      <deleteFlag/>
   </Process>
   <Process>
      <Title>Process 2</Title>
      <Description/>
      <Tech_ID>20</Tech_ID>
      <lastUpdate/>
      <deleteFlag/>
   </Process>
</ImportSchemaBase>

The desired output would be (with the extracted content out of CDATA):

   <ImportSchemaBase>
       <Process>
          <Title>Process 1</Title>
          <Description>Some description 1</Description>
          <Tech_ID>10</Tech_ID>
          <lastUpdate/>
          <deleteFlag/>
       </Process>
       <Process>
          <Title>Process 2</Title>
          <Description>Some description 2</Description>
          <Tech_ID>20</Tech_ID>
          <lastUpdate/>
          <deleteFlag/>
       </Process>
    </ImportSchemaBase>

I've tried also the "text()" matching pattern, but it didn't work and I read different answers and tried their approaches:

How to get CDATA from xml node using xsl and convert in a new XML?

How to get CDATA from xml node using xsl ?

How to parse an XML DOM inside a CDATA element in XSLT?

https://community.adobe.com/t5/framemaker/quot-unwrap-quot-cdata-with-xslt/td-p/1237978?page=1

http://vvratha.blogspot.com/2012/11/extracting-cdata-section-using-xslt.html

And I need to use XSLT 1.0.

Thanks for the help in advance and regards

1

1 Answers

1
votes

In your XML, description is a child element of process, not an attribute. To get its string-value, you must change:

<xsl:value-of select="@description"/>

to:

<xsl:value-of select="description"/>

or perhaps:

<xsl:value-of select="normalize-space(description)"/>

This has nothing to do with CDATA.