This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Default template match




Hello,
I have an XSL which has the purpose of "flattening out" some XML content,
getting personal data from another external file.
The output format is XML.
What I would like to do is treat some tags in a special way (for example, "sex"
will only output its content if the person for which I'm generating the output
is of the correct gender), and leave other tags unchanged in the output
document.
So I wrote several templates for all "active" tags (that correspond to a special
action), and a final "otherwise" template that simply copies the "non-active"
templates to the output.
The first question is, is it possible to define the default template without
that long line such as "match="node()[name() != 'adult' and name() != 'object'
and name() != 'content' and name() != 'gender']""?
Second question: my XSL is cycling through a list of persons in an XML doc, and
parsing a content document. To keep the reference to the correct person, I am
passing the reference to that person's data as a variable through all templates.
Is this the only way to do it (certainly not! :-) ? Are there more elegant ways
to do this?
Thank you,

Costantino

...
<xsl:template match="adult"> <!-- Output only if age > 17 -->
  <xsl:param name="doc-ref"/> <!-- pass the reference through the templates
recursively -->
  <xsl:if test="$doc-ref/customer/age &gt; 17">
    <xsl:apply-templates select="./*">
      <xsl:with-param name="doc-ref" select="$doc-ref"/> <!-- pass the reference
through the templates recursively -->
    </xsl:apply-templates>
  </xsl:if>
</xsl:template>

<xsl:template match="gender"> <!-- Output only if person of appropriate sex -->
  <xsl:param name="doc-ref"/> <!-- pass the reference through the templates
recursively -->
  <xsl:apply-templates select="current()[@gender = $doc-ref/customer/gender]/*">
    <xsl:with-param name="doc-ref" select="$doc-ref"/> <!-- pass the reference
through the templates recursively -->
  </xsl:apply-templates>
</xsl:template>

<!-- HOW DO I AVOID TO USE THIS HORRIBLE ROW, EXCLUDING ALL OTHER TEMPLATES? -->
<xsl:template match="node()[name() != 'paste' and name() != 'object' and name()
!= 'content' and name() != 'gender']">
  <xsl:param name="doc-ref"/> <!-- pass the reference through the templates
recursively -->
  <xsl:copy>
    <xsl:apply-templates select="node()">
      <xsl:with-param name="doc-ref" select="$doc-ref"/>
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>
...



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]