Question : XSLT Parsing pairs of xml tags

I'm using .net to output xml data via an xslt.

The xml doc looks something like this
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<top title="Interviews" interviewwith="Interview with" moreinterviews="More interviews">
      <record id="1">
      <holder>Some Dude</holder>
      <desc>Description</desc>
      <interview>
      <![CDATA[<q>Question </q><a>Answer</a><q>Question </q><a>Answer</a><q>Question </q><a>Answer</a>]]></record>
      </interview>
      </record>

      <record id="2">
      <holder>Some Dude</holder>
      <desc>Description</desc>
      <interview>
      <![CDATA[<q>Question </q><a>Answer</a><q>Question </q><a>Answer</a><q>Question </q><a>Answer</a>]]></record>
      </interview>
      </record>
</top>

Basically I am able output everything except the pairs of <q> and <a> within the <interview> tag?

Here is my xslt so far

<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:template match="/">
   

    <xsl:for-each select="top/record">
     
        <h2><xsl:value-of select="holder"/></h2>
        <p><xsl:value-of select="desc"/></p>
     
       <xsl:apply-templates select="interview"/>
     
    </xsl:for-each>

  </xsl:template>

  <xsl:template match="interview">
   
  </xsl:template>

</xsl:stylesheet>

Ideally I would like the output to be:

<h2>Some Due</h2>
<p>Description</p>

<h3>Question</h3>
<p>Answer</p>

<h3>Question</h3>
<p>Answer</p>

Thanks

D


Answer : XSLT Parsing pairs of xml tags

Honestly, it is a very bad idea to have wellformed XML flattened out as a text string by putting it in a CDATA section.
It then no longer IS XML, though it looks like it
If you ever need that XML to be processed as XML you have to deserialize it again.
It is a bad idea.

If you can, you should change the XML at the source and not have the CDATA section, that would be the way to go

If that can't be done, I would introduce a normalisation step.
This means that you would have two XSLTs in a row.
The first XSLT would be the one I attached.
After that the CDATA would be gone because of the disable-output-escaping

After that you can use your XSLT on good data

I hope you can set up a series of XSLTs.
If that can't be done, you will need some complex recursive text processing.
XSLT is not meant for that, but if you need this third option, I will write one to show you how
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
	version="1.0">

  <xsl:template match="node()">
  	<xsl:copy>
  		<xsl:copy-of select="@*"/>
  		<xsl:apply-templates select="node()"/>
  	</xsl:copy>
  </xsl:template>

  <xsl:template match="interview">
  	<xsl:copy>
  		<xsl:copy-of select="@*"/>
  	<xsl:value-of disable-output-escaping="yes" select="."/>
  	</xsl:copy>
  </xsl:template>

</xsl:stylesheet>
Random Solutions  
 
programming4us programming4us