Re: spot/remove repeated elements in XML documet
Michael Ludwig <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
Manuel Souto Pico schrieb:
>
> Thanks for your reply. Indeed, XSLT seems like the easiest option to
> do this processing. However, I don't have enough knowledge about XLST
> in order to understand well some things in your proposal, I might need
> to study a bit...
Go to the XSL-List at Mulberrytech.COM for learning more.
> I will ask about one only: <xsl:variable name="unlikely"
> select="'||--||'"/>. I understand this is what might be between
> elements Eng and Spa, but I don't understand the '||--||'. Could you
> explain?
It is just some string unlikely to occur in your dictionary terms.
Basically, it's a hack, but it'll work. If Eng is "aa" and Spa is "b",
then this is not the same as when Eng is "a" and Spa is "ab". So in
order to concatenate them to different strings, introduce a separator.
And that would have been a better name for that variable, by the way.
> Anyway, I tried to use your template to process my example (which is a
> simplified version of the document that I need to process) but I get
> some errors (in Oxygen).
Okay. I thought you were going to use Perl. I don't know which processor
your version of Oxygen embeds.
> Using XSLT 1.0, the line <xsl:key name="dupl" match="entry"
> use="concat( Eng, $unlikely, Spa)"/> gives the error: "The expressions
> in xsl:key may not contain references to variables".
Then replace $unlikely by its contents.
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
> <xsl:key name="eng-by-content" match="entry/Eng" use="."/>
> <xsl:key name="spa-by-content" match="entry/Spa" use="."/>
> <xsl:template match="/dictionary">
> <dictionary>
> <xsl:for-each select="entry/Eng">
> <xsl:if test="generate-id(.) =
> generate-id(key('eng-by-content', .)[1]) ">
Looks like identity is defined by the English term only. If that's what
you want, that's probably fine.
> This XSL sheet allows me to output only the entries with no duplicate
> English term (say, 1 and 2), and that's already something.
Okay.
> I've tried applying your concatenation syntax but I can't manage to
> use both languages as criteria
Try applying the correction I suggested above.
> Thanks a lot for your help!
You're very welcome.
Michael Ludwig
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs