xsl-list
[Top] [All Lists]

RE: xsl pipeline filters

2003-01-21 12:11:49
If I understand your question, there are really two questions:
1) How do I create a pipeline of transformations?
2) How do I select specific elements from the input document for inlcusion in 
the output document at each transformation?

I'll address the latter question first.

Given an input document:
<SITES>
 <CONTENT>
  <LAN>1</LAN>
  <LEVEL>1</LEVEL>
  <DISPLAY>1</DISPLAY> 
  <TITLE>PHILOPAPPOU MONUMENT</TITLE>
  <TEXT>hello</TEXT>
  <IMAGE></IMAGE>
 </CONTENT>
 <CONTENT>
  <LAN>1</LAN>
  <LEVEL>2</LEVEL>
  <DISPLAY>1</DISPLAY>   
  <TITLE>PHILOPAPPOU MONUMENT</TITLE>
  <TEXT>It is found in the ...</TEXT>
  <IMAGE></IMAGE>
 </CONTENT>
<CONTENT>
<!-- .... more CONTENT elements -->
</SITES>

So i want the first xsl to filter the language and 
to keep only the first three tags(where lan=1 or when lan=2)

If you mean that you want to copy those CONTENT elements whose LAN child has a 
value of '1' or '2', this template will filter out any CONTENT elements whose 
child LAN does not have a value of 1 or 2.

 <xsl:template match="CONTENT[child::LAN='1' or child::LAN='2']">
  <xsl:copy-of select="." />
 </xsl:template>

the second one to filter only the
content with level=2 (for example)

This addition to the template will further restrict the nodes copied

<xsl:template match="CONTENT[child::LAN='1' or 
child::LAN='2'][child::LEVEL='2']">
  <xsl:copy-of select="." />
</xsl:template>

If instead you mean that you want to copy only the CONTENT elements and produce 
an element in the output tree like this:

<CONTENT>
 <LAN>1</LAN>
 <LEVEL>2</LEVEL>
</CONTENT>

You could use this template:

<xsl:template match="CONTENT[child::LAN='1' or 
child::LAN='2'][child::LEVEL='2']">
  <xsl:element name="CONTENT">
    <xsl:element name="LAN"><xsl:value-of select="./LAN" /></xsl:element>
    <xsl:element name="LEVEL"><xsl:value-of select="./LEVEL" /></xsl:element>
  </xsl:element>
</xsl:template>

and the last one to show the text as html
output(if display is set to 2).

This is not difficult. I would have included code if you had said what HTML 
elements you wanted to produce.

Going back to the first question, do you really need an external pipeline? Or 
could you do what I showed here and use only XSLT to select just those elements 
you want to pass along?
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email


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



<Prev in Thread] Current Thread [Next in Thread>