On 8 August 2011 18:52, Darius Jazayeri <[email protected]> wrote:
> Bob,
> This helps a lot, I wasn't aware of the identity template.
> Perhaps this is also a 2-second answer for you...what if I want to remove an
> element, and add a different element to its ancestor. Specifically, if I
> find a conceptName with tags/conceptNameTag[tag='preferred'] I want to
> remove that and add <conceptNameType>FULLY_SPECIFIED</conceptNameType> to
> the conceptName.
> E.g. changing this:
> <conceptName>
> <tags>
> <conceptNameTag>
> <tag>preferred</tag>
> </conceptNameTag>
> </tags>
> </conceptName>
> To this:
> <conceptName>
> <tags/>
> <conceptNameType>FULLY_SPECIFIED</conceptNameType>
> </conceptName>
> I can think of several very verbose ways to do this, but I imagine there's a
> concise one that uses a command I'm not aware of...
Again identity template is your friend. Keep everything as before
with identity template passing through the default. Then add a more
specifically matching template like:
<xsl:template match="conceptName[tags/conceptNameTag/tag='preferred']">
<conceptName>
<tags/>
<conceptNameType>FULLY_SPECIFIED</conceptNameType>
</conceptName>
</xsl:template>
This *should* (not tested) match any conceptName with tag='preferred'.
And write out a new conceptName as above. What do you want to do
with any other tags you might have? The above simply ignores them.
Cheers
Bob
>
> On Mon, Aug 8, 2011 at 8:32 AM, Bob Jolliffe <[email protected]> wrote:
>>
>> Hi Darius
>>
>> You want to use identity template to copy through everything. Then
>> have a template which matches the ones you want removed which simply
>> outputs nothing. The more specific match will override the general
>> one. Something like the following will work:
>>
>> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
>> version="1.0"><xsl:output method="xml"/>
>>
>> <xsl:template match="/">
>> <xsl:apply-templates />
>> </xsl:template>
>>
>> <!-- Default is copy all nodes -->
>> <xsl:template match="@*|node()">
>> <xsl:copy>
>> <xsl:apply-templates select="@*|node()"/>
>> </xsl:copy>
>> </xsl:template>
>>
>> <!-- Except ....-->
>> <xsl:template match="concept[remove]" />
>>
>> </xsl:stylesheet>
>>
>> Note this matches any concept which has a <remove> child. You could
>> be more specific with something like:
>> <xsl:template match="concept[remove/@apply='true']" />
>> which matches your description, or any other condition you like.
>>
>> Cheers
>> Bob
>>
>>
>>
>>
>> On 8 August 2011 15:50, Darius Jazayeri <[email protected]> wrote:
>> > Hey Burke,
>> > I am having a lot of trouble with what I assumed would be a
>> > straightforward
>> > application of XSLT, and I haven't been able to find an example of this
>> > on
>> > the web. Can you help me out here? The contrived simplified version is:
>> > I want to remove any concept that has a <remove> tag as a child, and
>> > pass
>> > through all other tags exactly as they are. (More realistically I want
>> > to
>> > only do so if some further condition holds for its attributes, but that
>> > should be easy if I can figure out how to pass everything through that
>> > doesn't match my main translation.)
>> > Example source:
>> > <concepts>
>> > <concept id="1"/>
>> > <concept id="2"/>
>> > <concept id="3"/>
>> > <remove apply="true"/>
>> > </concept>
>> > <concept id="4"/>
>> > </concepts>
>> > Desired output
>> > <concepts>
>> > <concept id="1"/>
>> > <concept id="2"/>
>> > <concept id="4"/>
>> > </concepts>
>> > Thoughts?
>> > -Darius
>> > ________________________________
>> > Click here to unsubscribe from OpenMRS Developers' mailing list
>>
>> _________________________________________
>>
>> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> [email protected] with "SIGNOFF openmrs-devel-l" in the body (not
>> the subject) of your e-mail.
>>
>> [mailto:[email protected]?body=SIGNOFF%20openmrs-devel-l]
>
> ________________________________
> Click here to unsubscribe from OpenMRS Developers' mailing list
_________________________________________
To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
[email protected] with "SIGNOFF openmrs-devel-l" in the body (not
the subject) of your e-mail.
[mailto:[email protected]?body=SIGNOFF%20openmrs-devel-l]