xsl-list
[Top] [All Lists]

Re: [xsl] Applying an XSLT-file to specific nodes within an XML file

2009-07-16 16:53:46
Mark,

It's hard to say exactly where you'd need to put this without seeing
how your XSLT is laid out, but I think you can get what you want by
placing something like this in the right place:

     <xsl:apply-templates select="//msDesc[msItem/title = 'AAAA']"/>

If you can place this in the template that processes your "mss"
element, you can drop the "//" at the beginning of the select
expression, which would be better for performance.  If it needs to go
somewhere else, you'll need to modify the expression a bit
differently.

-Brandon :)

Brandon Ibach
Developer, Single-Sourcing Solutions, Inc.

On Thu, Jul 16, 2009 at 4:22 PM, Mark 
Aussems<mark(_dot_)aussems(_at_)gmail(_dot_)com> wrote:
Hi all,

Hopefully someone can assist me in solving a (probably rather basic) problem
related to restricting the execution of an XSLT file to a specific part of
an XML file.

My XML file looks like this (very simplified):

<mss>
     <msDesc>
             <msItem>
                     <title>AAAA</title>
             </msItem>
     </msDesc>
     <msDesc>
             <msItem>
                     <title>BBBB</title>
             </msItem>
     </msDesc>
     <msDesc>
             <msItem>
                     <title>CCCC</title>
             </msItem>
     </msDesc>
</mss>

I have written an XSLT file which transforms my entire XML into a nice HTML
file. I would now like to restrict the XSLT file so that it ONLY transforms
the <msDesc> nodes which have a <title> tag with the value 'AAAA'. So, in
simpler terms, I would like to say to my XSL file:

1. Find all <msDesc> nodes which have a <title> tag with the value 'AAAA'.
2. Apply the following <xsl:template>  transformations, but only to the
<msDesc> nodes specified above.
3. [And then all my <xsl:template> transformations]

A possible solution to this would be to write a simple XQuery script to
extract the relevant <msDesc> nodes and put them in a separate XML file,
which can then be transformed. That requires a lot of manual labour
(especially since my titles go from AAAA to PPPP...), so I was wondering
whether there is a work-around or short-cut within XSL?

I hope this makes sense. I'm sure there's something obvious I'm missing...

Many thanks in advance,
Mark


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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