Hi and thanks for responding,

[more comments questions below. I realize it has been a while since you touched this, so thanks in advance for any answers from you or anyone else. They are not really important, just curious.]

Geir Magnusson Jr wrote:


Robert Koberg wrote:

Geir Magnusson Jr wrote:

The velocity aspect - templating - is the same. What it's meant to do is simply use the declarative model of XSL (which *is* complicated) and let you use Velocity to do the rendering.


Hi,

I just had a look at this again after using Velocity for a year or two. I can see some way to use this inside a Velocity template/page very nicely. I believe I know XSL 1.0 pretty well. I can see how some things in Velocity proper can replace some things in XSL so they do not need to be repeated there. I have some quick questions questions off the top of my head:

- how are namespaces handled? how do you declare them? Is XPath fully supported (uses Jaxen perhaps?)?


It was a while ago... we were just using what was in dom4j, and that was jaxen, IIRC

OK. In dom4j/jaxen you have to set the namespaces to use them in an XPath expression, for example:

org.dom4j.xpath.DefaultXPath xpath = new DefaultXPath(xpathStr);
xpath.setNamespaceURIs(namespacesMap);

The map is setup so that the keys are the prefixes and the values are the URIs.

You can also set a namespace context with a org.jaxen.NamespaceContext.



- are there modes and named templates?


That question I don't understand.


In XSL you apply-templates in a mode so you can do different things with the same node, for example:

<xsl:template match="*" mode="nav-tree">
  <li>
    <p><xsl:value-of select="@label"/></p>
    <xsl:if test="*">
      <ol>
        <xsl:apply-templates mode="nav-tree"/>
      </ol>
    </xsl:if>
  </li>
</xsl:template>

This is matching someElem and building up a nested ordered list. It will test if there are children elements and if so continue nesting by only send the flow to templates that have a mode="nav-tree".

Also in XSL you can have named templates, for example:
...
<html>
  <xsl:call-template name="head"/>
  <xsl:call-template name="body"/>
</html>
...

Which would, for instance, call:

<xsl:template name="head">
...
</xsl:template>

This jogs another question :) Can you call-template's and apply-templates with a param, for example:

...
<xsl:apply-templates>
  <xsl:with-param name="param-a" select="'string'"/>
  <xsl:with-param name="param-n" select="node"/>
</xsl:apply-templates>
...

<xsl:template match="*">
  <xsl:param name="param-a" select="'default'"/>
  <xsl:param name="param-n" select="'defaultx'"/>
...
</xsl:template>



- can you do something like:

#if ($foo)
  #match("foo")$context.applyTemplates()#end
#else
  #match("*")$context.applyTemplates()#end
#end


That would be cool, and (again, it's been a while, so YMMV) I think it should. Of course, we'd want some kind of scope, I suspect, so that it's not global but only applied to some local context of processing, I would guess.

In XSL, you would do:

<xsl:template match="possibleFooParent">
  <xsl:choose>
    <xsl:when test="fooElem">
<!--
If the elem 'possibleFooParent' has a child named fooElem it would come in here. Oh, I see below that testing for nodes is not possible.
-->
...
    </xsl:when>
    <xsl:otherwise>
...
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>



- can you use the XML nodes in a conditional. For example say I have a source like:

<foo bar="something"/>

Can an if be like an XSL if testing the existence of the bar attribute like:

#if (@bar)
  do something...
#end


No. There is no modification to the core Velocity for this - the idea was to use stock and standard velocity with a framework for VM invocation as you wander about the document. That's all.

If you are interested in it..... thanks for volunteering!  Patches welcome!

I think I am going to stick with XSL. I think I mentioned this before, but you could use a toolbox tool to do a transformation using XSL and return the result to velocity. Or you could do it in a servlet filter and put it in the context.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to