473,378 Members | 1,384 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

supress matching

Suppose I have the following xml-text:

Some text before.<A/>
<B>Text in the B-element.</B>
Some text after.

And I want:

Some text before.
<C>Text in the B-element.</C>
Some text after

I have tried something like:

<xsl:template match="A">
<C><xsl:apply-templates select="B"/></C>
</xsl:template>

<xsl:template match="B">
<xsl:apply-templates/>
</xsl:template>

But that results in:

Some text before.
<C>Text in the B-element.</C>
Text in the B-element.
Some text after

So basically, how can I call template B from
within template A, and then not having B match
again?

Jan 9 '07 #1
6 1452
pa**********@orient.su.se wrote:
Suppose I have the following xml-text:

Some text before.<A/>
<B>Text in the B-element.</B>
Some text after.
That stuff is not well-formed. At least show us the element that markup
is contained in.
And I want:

Some text before.
<C>Text in the B-element.</C>
Some text after
So you want to remove the empty A element, you want to replace the B
element with a C element but preserves its content. And you want to
copy text nodes outside of B. So doing e.g.

<xsl:template match="A"/>

ignores the A elements,

<xsl:template match="B">
<C>
<xsl:apply-templates/>
</C>
</xsl:template>

transforms B into C elements and the built-in template

<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>

copies text nodes.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 9 '07 #2
pa**********@orient.su.se wrote:
Suppose I have the following xml-text:

Some text before.<A/>
<B>Text in the B-element.</B>
Some text after.

And I want:

Some text before.
<C>Text in the B-element.</C>
Some text after

I have tried something like:

<xsl:template match="A">
<C><xsl:apply-templates select="B"/></C>
</xsl:template>

<xsl:template match="B">
<xsl:apply-templates/>
</xsl:template>

But that results in:

Some text before.
<C>Text in the B-element.</C>
Text in the B-element.
Some text after

So basically, how can I call template B from
within template A, and then not having B match
again?
<xsl:template match="A"/>

<xsl:template match="B">
<C>
<xsl:apply-templates/>
</C>
</xsl:template>
// Magnus
Jan 9 '07 #3
OK, sorry, I tried to make it short, but it became
confusing instead. Here's the whole story.

I'm working with a text that contains the following
structures:

<p>
Some lines of text.
Some lines of text. *)
</p>

<footnote>
Text in the footnote. It continues ...
</footnote>

<pagebreak/>

<p>
Some more lines of text.
</p>

<footnote>
... in the next footnote element!
</footnote>

I need to preserve this structure, but I also need to
be able to output

Some lines of text.
Some lines of text. *)\footnote{%
Text in the footnote. It continues ...
... in the next footnote element!
}

Some more lines of text.

To this end, I apply the following markup:

<p>
Some lines of text.
Some lines of text. *)<fn n="1"/>
</p>

<footnote n="1">
Text in the footnote. It continues ...
</footnote>

<pagebreak/>

<p>
Some more lines of text.
</p>

<footnote n="1">
... in the next footnote element!
</footnote>

I have tried the following templates:

<xsl:template match="fn">
<xsl:param name="notenr" select="@n"/>\footnote{%
<xsl:apply-templates select="following::fotnottext[@n eq
$notenr]"/>}
</xsl:template>

<xsl:template match="footnote">
<xsl:apply-templates/>
</xsl:template>

But I get:

Some lines of text.
Some lines of text. *)\footnote{%
Text in the footnote. It continues ...
... in the next footnote element!
}

Text in the footnote. It continues ... <-----

Some more lines of text.

... in the next footnote element! <-----

The lines marked with <----- must be removed somehow.
I hope this makes it clearer what I want.

Jan 9 '07 #4
Read about the "mode" attribute of the <xsl:templateinstruction and of the
<xsl:apply-templatesinstruction.

Then use this attribute in your XSLT code.
Cheers,
Dimitre Novatchev

<pa**********@orient.su.sewrote in message
news:11*********************@s34g2000cwa.googlegro ups.com...
OK, sorry, I tried to make it short, but it became
confusing instead. Here's the whole story.

I'm working with a text that contains the following
structures:

<p>
Some lines of text.
Some lines of text. *)
</p>

<footnote>
Text in the footnote. It continues ...
</footnote>

<pagebreak/>

<p>
Some more lines of text.
</p>

<footnote>
... in the next footnote element!
</footnote>

I need to preserve this structure, but I also need to
be able to output

Some lines of text.
Some lines of text. *)\footnote{%
Text in the footnote. It continues ...
... in the next footnote element!
}

Some more lines of text.

To this end, I apply the following markup:

<p>
Some lines of text.
Some lines of text. *)<fn n="1"/>
</p>

<footnote n="1">
Text in the footnote. It continues ...
</footnote>

<pagebreak/>

<p>
Some more lines of text.
</p>

<footnote n="1">
... in the next footnote element!
</footnote>

I have tried the following templates:

<xsl:template match="fn">
<xsl:param name="notenr" select="@n"/>\footnote{%
<xsl:apply-templates select="following::fotnottext[@n eq
$notenr]"/>}
</xsl:template>

<xsl:template match="footnote">
<xsl:apply-templates/>
</xsl:template>

But I get:

Some lines of text.
Some lines of text. *)\footnote{%
Text in the footnote. It continues ...
... in the next footnote element!
}

Text in the footnote. It continues ... <-----

Some more lines of text.

... in the next footnote element! <-----

The lines marked with <----- must be removed somehow.
I hope this makes it clearer what I want.

Jan 9 '07 #5
In article <11********************@11g2000cwr.googlegroups.co m>,
<pa**********@orient.su.sewrote:
Some text before.<A/>
<B>Text in the B-element.</B>
Some text after.

And I want:

Some text before.
<C>Text in the B-element.</C>
Some text after

I have tried something like:

<xsl:template match="A">
<C><xsl:apply-templates select="B"/></C>
</xsl:template>

<xsl:template match="B">
<xsl:apply-templates/>
</xsl:template>
You can't be doing that! The B is not inside the A so select="B"
won't select anything. Presumably you are using following-sibling or
something similar.

You could change the template of the element containing A and B to
not call apply-templates on B - perhaps:

<xsl:apply-templates select="*[not(self::B)]"/>

or you could use modes. Have a plain template for B that does nothing,
and a template in mode really-do-it:

<xsl:template match="B" mode="really-do-it">
<xsl:apply-templates/>
</xsl:template>

Then have the template for A call apply-templates on B with
mode="really-do-it".

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jan 9 '07 #6
Richard Tobin wrote:
You can't be doing that! The B is not inside the A so select="B"
won't select anything. Presumably you are using following-sibling or
something similar.
You're right, of course. I over-simplified my example.
or you could use modes. Have a plain template for B that does nothing,
and a template in mode really-do-it:
Yes, that does it. Wonderful! Thanks a lot to all who answered.

/Patrik

Jan 9 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LRW | last post by:
I'm creating a simple reply form, and if a form item isn't answered I get an error: "Notice: Undefined index: rb_amntspent in c:\inetpub\wwwroot\mackinaw\survey.php on line 36" even if in the...
1
by: roderik | last post by:
How do I supress the output generated from each psycopg command: >>> import psycopg initpsycopg: initializing psycopg 1.99.10 typecast_init: initializing NUMBER .. .. microprotocols_add:...
1
by: David | last post by:
I have a custom control that contains a class that Inherits the panel control. I am trying to catch a keydown event in this class and then supress it from the rest of the control as well as the...
3
by: JG | last post by:
Hi all, I have a simple aspx page. On the page there is only one button. When I click on the button, the event sequence is Page_Load, Button1_click and Page_PreRender. How do I supress the...
2
by: Still Learning | last post by:
Hi, Currently a crystal report is getting 359.9999 from a dataset. Even with rounding set to 0.0001 it displays 360.0 which is wrong. How can I supress rounding or get it to display 359.9999? ...
4
by: rob c | last post by:
This is a minor thing and only appears in IE (so far), but I'd like to know to correct it (if possible). Whenever I use a form on a webpage, Explorer always leaves a blank line following the...
1
by: Nikhil Mittal | last post by:
How to supress system errors in windows perl In unix it is 2>&1 , what is in windows :o
2
by: =?Utf-8?B?Q2hyaXMgRGF2b2xp?= | last post by:
I have to zero supress some numbers ie; 20.000000000 or 20.0100000 What is an easy way to do this? If I got to write code, is there some code examples out there? -- Chris Davoli
2
by: khani | last post by:
Hi i have following situation in cystal report in detail section i have a field say name.now i have five duplication record like this zahid zahid zahid zahid
6
by: Proaccesspro | last post by:
Hello All, I have a report that is tied to a SELECT query.....Problem is, when I open the report, it also opens the results of the select query. Is there a way to supress the Query from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.