[j-nsp] How to trim the text node of a specific element node in SLAX node-set?
Phil Shafer
phil at juniper.net
Thu Oct 25 15:09:29 EDT 2018
Martin T writes:
>I need to trim the text node of a specific element node in SLAX. All
>other elements should remain as in the original node-set. At the
>moment, I do it like this:
Use apply-templates and a distinct mode to traverse the entire
hierarchy and apply rules to rebuild content, like:
version 1.2;
main <top> {
var $alphabet := <letters> {
<consonants> {
<b pos="2"> "bbb ";
<c pos="3"> "ccc ";
}
<consonants> {
<d pos="4"> "ddd ";
<f pos="5"> "fff ";
}
}
var $new = {
apply-templates $alphabet {
mode "trim";
}
}
<new> { copy-of $new; }
}
match text() {
mode "trim";
if (name(..) == "d") {
<d pos="4"> translate(., " ", "");
} else {
copy-of .;
}
}
match @* | * | processing-instruction() | comment() {
mode "trim";
copy-node {
apply-templates * |@* | text() | processing-instruction() | comment() {
mode "trim";
}
}
}
Thanks,
Phil
More information about the juniper-nsp
mailing list