Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem creating tags 1

Status
Not open for further replies.

sheila11

Programmer
Dec 27, 2000
251
US
Hi all,

I have to generate a two-column table using xslt.

My xsl code is:
<xsl:for-each select="my-tag">
<xsl:choose>
<xsl:when test="(position() mod 2) = 1">
--ADD tags <tr><td>
---add left cell here--
</xsl:when>
<xsl:when test="(position() mod 2) = 0">
---add right cell here--
--ADD tags </td></tr>
</xsl:when>
</xsl:choose>
<xsl:for-each>

But my <tr><td> tags come out as &lt;tr&gt; and &lt;td&gt;
which doesn't work in further usage of the output.

I tried using CDATA:
<xsl:text disable-output-escaping="yes"><![CDATA[ <tr>]]> </xsl:text>

But it still results the same.
Is there any work around ? Please advice me.

TIA,
Sheila

 
Post the proper stylesheet you are using. This is not well formed. What transformation engine are you using?
 
Here is the complete stylesheet:
--------------------------------
<xsl:stylesheet version = '1.0' xmlns:xsl=' >
<xsl:eek:utput method="xml" encoding="utf-8" version="1.0" omit-xml-declaration="no" />

<!-- for the rest to stay... Whenever anything matches, any node or any attribute -->
<xsl:template match=" / | @* | node() |processing-instruction()">
<xsl:processing-instruction name="xml">version="1.0" encoding="utf-8"</xsl:processing-instruction>
<xsl:copy>
<xsl:apply-templates select="@* | node() |processing-instruction()" />
</xsl:copy>
</xsl:template>

<xsl:template match="local-representative-list">
<xsl:element name="Table">

<xsl:for-each select="country-representative-entry">
<xsl:choose>
<xsl:when test="(position() mod 2) = 1">
<xsl:text disable-output-escaping="yes"><![CDATA[<tr><td>]]></xsl:text>
<xsl:apply-templates />
<xsl:text disable-output-escaping="yes"><![CDATA[</td>]]></xsl:text>
</xsl:when>
<xsl:when test="(position() mod 2) = 0">
<xsl:text disable-output-escaping="yes"><![CDATA[<td>]]></xsl:text>
<xsl:apply-templates />
<xsl:text disable-output-escaping="yes"><![CDATA[</td></tr>]]></xsl:text>
</xsl:when>
</xsl:choose>
</xsl:for-each>


</xsl:element>
</xsl:template>

</xsl:stylesheet>
--------------------------------
The problem is that I get:
<Table>&lt;tr&gt;&lt;td&gt;
and am not able to use it like <Table><tr><td>.

Another problem is that the declaration doesn't appear in output-xml inspite of adding omit-xml-declaration="no" in output.

Thanks for your attention,
Sheila
 
I forgot to mention, I am running this in C#, ( using System.Xml.Xsl; ).
 
How about something like this:
Code:
<xsl:for-each select="country-representative-entry[position() mod 2 = 1]">
  <tr>
    <td>
      <xsl:apply-templates select="."/>
    </td>
    <td>
      <xsl:apply-templates select="following-sibling::*[1]"/>
    </td>
  </tr>
</xsl:for-each>

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
That works like a charm :) Thank you so much !!!

Could you also advice me on getting declaration in the output?

Thanks once again,
Sheila
 
Thats probably a .net issue. Whats your code?

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
XmlDocument xDoc = getXMLDoc("C:\\ProjectName\\Input.xml");

string xslPath = "C:\\XslFolder\\MakeTblXsl.xsl";
XslTransform xslTransform = new XslTransform();
XslTransform.Load(xslPath);

XmlUrlResolver xmlResolver = null;
XmlTextWriter xWrter = new XmlTextWriter("C:\\Path\\OutMassaged-test.xml", null);

xslTransform.Transform(xDoc, null, xWrter);
xWrter.Close();
 
Thanks for the hint, JontyMC. I supplied XPathNavigator to the XslTransform object, and it created the declaration correctly.

Thanks again,
Sheila
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top