Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Use XSL To Add A New Element

796254Aug 11 2004 — edited Aug 31 2004
I'm having trouble with what should be a simple XSL stylesheet.

I'd like to take an input XML document and add a new element based on matching the input stream. Here's my first attempt at a stylesheet that's failing:
<!--
A simple stylesheet for adding a tag to a document 
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


    <!-- Copy the document in its entirety -->
    <xsl:template match="*|@*|comment()|processing-instruction()|text()">
        <xsl:copy>
            <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
        </xsl:copy>
    </xsl:template>
    
    
    <!--  Find the queryItem tag and add a promptInfo child -->
    <xsl:template match="queryItem">
    
        <xsl:copy>
            <xsl:apply-templates />
        </xsl:copy>

        <promptInfo>
            <promptType>selectWithSearch</promptType>
        </promptInfo>

    </xsl:template>

</xsl:stylesheet>
When I run this through Xalan I get the original stream back, without any new tags added. (I'm certain that there's a <queryItem> element in my XML input.) It's as if the match at the top is "too strong" and is executed regardless of the presence of the more specific request to match queryItem.

How do I rewrite this stylesheet to copy the entire document and still honor the match for <queryItem>?

%
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 28 2004
Added on Aug 11 2004
12 comments
260 views