[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Filtering XML elements based on tokenized external parameters?


Subject: RE: [xsl] Filtering XML elements based on tokenized external parameters?
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Fri, 17 Jun 2005 16:59:40 +0000

Ramon,

You'll probably get many suggestions on approaching this as you describe -- pass in XSL parameters, and have the main stylesheet figure out what to emit.

I'm writing to propose an alternative -- especially since you may use a script to glue together things, the school of thought that has programs writing programs would have you consider writing a script or transform that, given your input "parameters", would then automatedly and dynamically construct a special-purpose XSL stylesheet that, applied against your original input XML, would output the nodes you want.

Regards,

--A

From: "Ramon Felciano" <felciano@xxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: [xsl] Filtering XML elements based on tokenized external parameters?
Date: Fri, 17 Jun 2005 09:44:00 -0700



Hello --


I'm trying to do parameterized XSLT-based filtering to strip out
unwanted structure from an XML file. The XML file represents a graph
data structure along with some other metadata. Conceptually I want to
extract a subgraph from this data structure, but want to do so in an
upwards-compatible way such that any additional tags in the XML are
carried over to the resulting document. For example, given this XML
file:

<graph>
    <node id="alpha"/>
    <node id="beta"/>
    <node id="delta"/>
    <node id="gamma"/>
    <edge from="alpha" to="delta"/>
    <edge from="alpha" to="beta"/>
    <edge from="alpha" to="gamma"/>
    <edge from="beta" to="beta"/>
    <mymetadata id="123"/>
</graph>

Given the above simple graph data structure, I want to produce a
filtered version that only includes node elements (ideally both node and
edge elements) that match a given set of input parameters, as well as
any other tags that might be included (e.g. the mymetadata tag). I'd
ideally like to issue a call like this so that I integrate this w shell
scripts:

xsltproc mytransform.xslt myfile.xml --param nodelist "alpha,beta"

And get this back:

<graph>
    <node id="alpha"/>
    <node id="beta"/>
    <edge from="alpha" to="beta"/>
    <edge from="beta" to="beta"/>
    <mymetadata id="123"/>
</graph>

I have two questions:

1. What is the best way to create a pattern match that is parameterized
based on the incoming nodelist? I'd like to flexible about delimeters
(e.g. have both "alpha,beta" and "alpha   ,   beta" work). I've tried
playing with tokenize from EXSLT but can't figure how to use the
resulting tokens to implement the filtering in a single-pass.

2. Is there a way to implement this to also include the alpha-gamma edge
and the gamma node, based on the partial edge match to "alpha"? I know
how to do this w multiple passes (e.g. by marking the edges, then the
nodes, then filtering) but was wondering if there was a nice one-pass
functional approach I've missed.

Thank you in advance for your time.

Ramon

_________________________________

Ramon M. Felciano
INGENUITY Systems, Inc.


_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



Current Thread
Keywords