XST converting XML to HTML question

B

Bill Sneddon

I am using an XML file produced by doing a save-as in Excel. The file
has content that looks like one of these three examples lines:

<Cell ss:StyleID="s24"><ss:Data ss:Type="String"
xmlns="http://www.w3.org/TR/REC-html40">H<Sub>3</Sub><Font>PO</Font><Sub>4
</Sub></ss:Data></Cell>

<Cell ss:StyleID="s24"><Data ss:Type="String">GC</Data></Cell>

<Cell ss:StyleID="s24"><ss:Data ss:Type="String"
xmlns="http://www.w3.org/TR/REC-html40">I<Sub>CC</Sub></ss:Data></Cell>


What I would like to do is produce html that formats the subscript
properly. For example I would like to display H3PO4 with the 3 & 4
subscripted like this H<Sub>3</Sub><Font>PO</Font><Sub>4</Sub>

when I do this select <xsl:value-of select="Cell[1]"/>
I get H3PO4 back. I<Sub>CC</Sub> would also be valid data so
I can't make assuptions about the number of <Sub> tags and where they
might be in the data.

I am not sure if the solution to this is easy or not. I still trying to
understand XSL and may be overlooking something.



Bill
 
B

Bill Sneddon

I could not make this work at all.
I finally had to convert <Sub> -> &lt;Sub&gt;
Do the transform and convert it back.

It still seems possible but I could not get it to work after many attempts.

In your example below what causes the H and the 3 to be outputed?
I am currently working in a for-each loop but had the same results
when trying to apply templates.

<Data>H<Sub>3</Sub><Font>PO</Font><Sub>4
</Sub></ss:Data></Cell>


Bill

Peter said:
Bill said:
I am using an XML file produced by doing a save-as in Excel. The file
has content that looks like one of these three examples lines:

<Cell ss:StyleID="s24"><ss:Data ss:Type="String"
xmlns="http://www.w3.org/TR/REC-html40">H<Sub>3</Sub><Font>PO</Font><Sub>4
</Sub></ss:Data></Cell>

<Cell ss:StyleID="s24"><Data ss:Type="String">GC</Data></Cell>

<Cell ss:StyleID="s24"><ss:Data ss:Type="String"
xmlns="http://www.w3.org/TR/REC-html40">I<Sub>CC</Sub></ss:Data></Cell>


What I would like to do is produce html that formats the subscript
properly. For example I would like to display H3PO4 with the 3 & 4
subscripted like this H<Sub>3</Sub><Font>PO</Font><Sub>4</Sub>

when I do this select <xsl:value-of select="Cell[1]"/>
I get H3PO4 back.


That's because value-of gives you the string content, stripped
of any internal markup. You need to write a template for Cell
and for Sub:

<xsl:template match="Cell">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="Sub">
<sub>
<xsl:apply-templates/>
</sub>
</xsl:apply-templates>

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top