I am inserting a new element into an existing xml, I get my xpaths (where the element should be inserted) in an xml file, so I wrote a program that generates the XSLT script according to that input. Now whenever I am running it, it adds the elements to some xpaths and ignores the rest, I included all the namespaces that are being used, but what it's doing is that it's going to a certain hierarchy level and it doesn't go past it, at least this is what I am seeing. here is a snippet of the code for two templates one that inserts the element and the other that does not insert the element at all. Please tell me what I am doing wrong in here..
These are the templates that I can add due to the size:
<xsl:copy>
<flag sender="me" recipient="you" issueDateTime="02/14/2011">
<flagSubject> Error </flagSubject>
<message>
<p>r5 Designator Text is empty </p>
</message>
</flag>
<xsl:apply-templates select="@*| node()"/>
</xsl:copy>
</xsl:template>
<xsl:copy>
<flag sender="me" recipient="you" issueDateTime="02/14/2011">
<flagSubject> Error </flagSubject>
<message>
开发者_C百科 <p>r7 default title is blank </p>
</message>
</flag>
<xsl:apply-templates select="@*| node()"/>
</xsl:copy>
</xsl:template>
<xsl:copy>
<flag sender="me" recipient="you" issueDateTime="02/14/2011">
<flagSubject> Error </flagSubject>
<message>
<p>r7 default title is blank </p>
</message>
</flag>
<xsl:apply-templates select="@*| node()"/>
</xsl:copy>
</xsl:template>
<xsl:copy>
<flag sender="me" recipient="you" issueDateTime="02/14/2011">
<flagSubject> Error </flagSubject>
<message>
<p>r5 Designator Text is empty </p>
</message>
</flag>
<xsl:apply-templates select="@*| node()"/>
</xsl:copy>
</xsl:template>
<xsl:copy>
<flag sender="me" recipient="you" issueDateTime="02/14/2011">
<flagSubject> Error </flagSubject>
<message>
<p>r7 default title is blank </p>
</message>
</flag>
<xsl:apply-templates select="@*| node()"/>
</xsl:copy>
</xsl:template>
here is a snippet of the code for two templates one that inserts the element and the other that does not insert the element at all. Please tell me what I am doing wrong in here..
In the provided code there are two templates each overriding the identity rule/template for particular elements.
The fact that the first template "does not insert the element at all" means that there isn't any node that matches the match-pattern of this template.
If you provide the source XML document many people will show you that there isn't any such element in this XML document.
In case there are actually more templates (which you haven't shown), then another possible reason is that another template that also matches such elements was chosen due to higher priority -- and this other template probably doesn't do anything that would produce output.
The second template, in contrast, obviously matches element(s) from the source XML document and it does what it is intended to do.
Summary: The most likely problem with the first template is that it doesn't match any node in the XML document.
I found at least four namespace prefixes in your so-called XML that haven't been declared. At that point I gave up. This tells me two things: (a) the XML you posted is not the XML you are running against, and (b) you haven't understood that getting namespaces wrong is the most likely reason for XPath expressions (or XSLT match patterns) to fail to select anything.
精彩评论