[XML-SIG] dynamic information with xsl

Mike Brown mike@skew.org
Tue, 28 Jan 2003 01:24:36 -0700 (MST)

> > Suppose I wish to convert an xml source with a xsl stylesheet to html
> > output. While the conversion takes place, is it possible to have
> > something like an "external function call" to insert dynamic data like
> > date or "logged in" user for serverside formatting?

Despite the good advice to write an extension function, if the information
isn't going to be changing, you can pass it into the transformation as
top-level parameters. For example, using 4Suite 0.12.0a3 or latest code
from CVS:

SRC = """<?xml version="1.0"?><dummy/>"""

STY = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0"

  <xsl:param name="date" select="'unknown'"/>

  <xsl:output method="xml" indent="yes" encoding="us-ascii"/>

  <xsl:template match="/">
      <xsl:value-of select="$date"/>


import time
from Ft.Xml import InputSource
from Ft.Xml.Xslt import Processor

src_isrc = InputSource.DefaultFactory.fromString(SRC, 'http://foo/dummy.xml')
sty_isrc = InputSource.DefaultFactory.fromString(STY, 'http://foo/dummy.xsl')

proc = Processor.Processor()
params = {'date': time.asctime()}
result = proc.run(src_isrc, topLevelParams=params)
print result

Result of running the above (just a moment ago):

<?xml version="1.0" encoding="us-ascii"?>
<result>Tue Jan 28 01:22:47 2003</result>


  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/