Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

How to dynamically create or modify XSL

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am an XML beginner ..looking to create/modify an XSL document dynamically using a Java program..which will be applied to XML to generate HTML
In the example stylesheet which has been created manually ,I need to change the bgcolor and border properties of the 2 table tags. I dont know how to reference the appropriate table(Node).I know that XSL document can be created by any XML API ..but i find that too cumbersome. Is there any short cut(programmatically of course) by which i can modify the properties of the table nodes?I googled, but with little luck.
Can anyone please guide me the right solution.
Thanks a lot

/********************XSL document ****************************/


<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl utput method="html"/>
<xsl:template match="/">
<TITLE>MY REPORT</TITLE>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="query">
<br></br>
<b>DESCRIPTION OF THE TABLE IS AS FOLLOWS</b>
<br></br>
<table bgcolor="yellow" border="1">

<tr>
<th>COLNAME</th>
<th>DATATYPE</th>
</tr>

<xsl:for-each select="definition/element">
<tr>
<td><xsl:apply-templates/></td>
<td><xsl:value-of select="@type"/></td>
</tr>
</xsl:for-each>
</table>
<br> <b> Table Information</b></br>
<table bgcolor="cyan" border="1">
<tr>
<xsl:for-each select="definition/element">
<td><xsl:apply-templates/></td>
</xsl:for-each>
</tr>
<xsl:for-each select="data/row">
<tr>
<xsl:for-each select="*">
<td><xsl:apply-templates/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
/********************End of XSL document ****************************/
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem like a total XSLT newbie, so sorry if I go too fast (with instructions or that assumption). But, here are my points:

+ All use of XSLT is done with Java (doing the transformation). You can, however, create XSLT documents and write them however you want, e.g. Vi, Notepad, etc.
+ You can treat the transformation of an XSLT document the same as any other XML document, with the exception that you need to create an xslt-namespace-alias (I forget exact tag name), so it will not evaluate XSLT tags that you want merely written to the result stream.
+ Access elements within your transformed document with regular XPath expressions.

That should be a start. Honestly, I understood about 10% of what your problem was, so this may not be of any help to you. I'd recommend using zvon.org's website for a tutorial and reference on XSLT.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sumit,
you might want to look at the given problem. Your example is about changing colors etc. There you better use a customized CSS File, that is plain text. For processing the XML you have 2 options:
- Use something like JDOM to access the nodes to change them
- If you know in advance what parts of your stylesheet are supposed to change, you can use <xsl: param name="myownname" value="black" /> to define a parameter (use it with $myowname or "{$myownname}" depending where u use it).
This parameters (black is only the default value) can be supplied when you execute the XSLT transformation.
Hth
;-) stw
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic