[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML class descriptor



> >
> > It does.  Are you sure, though, that nobody will ever want to, say, run this
> > stuff through XSL for some reason?  Of course, one can parse a delimited
> > string in XSL as well, so there's not much in it.
> No, I'm not sure. What are the possible drawback of the current solution
> regarding XSL?
> 

It's not a big deal, but there is an issue of going with the natural
flow of the language features.  Processing lists of nodes in XSL is very
easy, and there is a range of idioms to support it including specifying
templates to match on given nodes in given contexts and explicit looping
like:

 	<xsl:for-each select="xparameter">
           ...
        </xsl:for-each>

Which selects all xparameter children of the current node (e.g., an
xmethod) and does the ... stuff to them with the xparameter set
temporarily to the current node.  If you wished, you could print a list
of all classes used as arguments in all methods and constructors by
saying something like:

 <xsl:for-each select="//xparameter">
   <xsl:sort select="."/>
   <xsl:if test="not(. = following-sibling::xparameter[1])">
     <xsl:message><xsl:value-of select="."/></xsl:message>
   </xsl:if>
 <xsl:for-each>

(XSL doesn't have good facilities yet for grouping/uniquing, hence the
following-sibling:: stuff.  Several of the processors have extension
functions which make complex grouping or node-set manipulation easier,
and additional facilities for these things are also intended for future
versions of XSL).

There are string-handling capabilities in XSL, but to parse the separate
parameters out of an attribute string you'd need to use a recursive
function, something like:

        <xsl:call-template name="do-params">
          <xsl:with-param name="parameters" select="@parameters"/>
        </xsl:call-template>

        <xsl:template name="do-params">
          <xsl:param name="parameters"/>
          <xsl:variable name="one-param" 
             select="string-before(parameters,'|')"/>
          <xsl:if test="string-length($one-param) > 0">
            <xsl:call-template name="do-to-one-param">
              <xsl:with-param name="one-p" select="$one-param"/>
            </xsl:call-template>
          </xsl:if>
          <xsl:variable name="next-params" 
            select="string-after(parameters,'|')"/>
          <xsl:if test="string-length($next-params) > 0">
            <xsl:call-template name="do-params">
              <xsl:with-param name="parameters"
                              select="$next-params"/>
            </xsl:call-template>
          </xsl:if>
        </xsl:template>

        <xsl:template name="do-to-one-param">
           <xsl:with-param name="one-p"/>
           ...
        </xsl:template>

So, you see, it's easier the element-way... (the above code is untested
by the way, and may be not only voluminous but also malfunctional).

 Steve