0

I have a xsl file, used as template,which i need to modify during runtime. I need to modify attribute value of a tag. Is there a way i can do it via JAVA code? I know the location of my template xsl file.

For instance:

Sample xsl template:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:template match="Sample">   
<HTML>
<HEAD>
</HEAD>
<BODY >
<APPLET ARCHIVE="http://localhost:500/abc.jar" CODE="test.class" NAME="Apps" ></APPLET>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>

Here i need to modify the APPLET tag, where i need to set the ARCHIVE value at runtime , say to be "http://localhost:800/xyz.jar"

Can i read this xsl file from Java somwhow and modify the atrribute for applet tag?

Archiekins
  • 30
  • 5
  • Since xsl is just xml, you can edit it as any xml in java http://stackoverflow.com/questions/7646607/how-to-modify-xml-tag-specific-value-in-java – Piro Oct 09 '13 at 08:33
  • @Piro Editing the stylesheet dynamically is the wrong thing to do. – Tomalak Oct 09 '13 at 08:42

1 Answers1

1

Use an XSL paramteter to transfer the value

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:xalan="http://xml.apache.org/xslt"
>
  <xsl:param name="archive" select="''" />

  <xsl:output method="html" indent="yes" />

  <xsl:template match="Sample">   
    <html>
      <head />
      <body>
        <applet archive="{$archive}" code="test.class" name="Apps" />
      </body>
     </html>
  </xsl:template>
</xsl:stylesheet>

Read up on how to pass XSL parameters in your XSLT engine. Saxon would use the XsltTransformer.SetParameter method, other engines work similarly.

By the way, ALL UPPERCASE HTML was last used in the 90's.

Tomalak
  • 332,285
  • 67
  • 532
  • 628