Project

Profile

Help

Removing processed processing instructions

Added by Anonymous about 18 years ago

Legacy ID: #3570713 Legacy Poster: Thomas (tbliem)

Hello, I have transformed an xml-file with saxon's "-a"-option and an <?xml-stylesheet ... ?> processing instruction. The resulting document still contains the <?xml-stylesheet ... ?>-line. Is this the intended behaviour? Is there a flag to delete this line? Thomas


Replies (5)

Please register to reply

RE: Removing processed processing instruction - Added by Anonymous about 18 years ago

Legacy ID: #3571055 Legacy Poster: Michael Kay (mhkay)

Nodes from the source document will only be copied into the result document if there's something in the stylesheet that copies them. Perhaps you have an identity template in your stylesheet that copies everything by default: if so, you can override it with one that doesn't copy processing instructions: <xsl:template match="processing-instruction()"/>

RE: Removing processed processing instruction - Added by Anonymous about 18 years ago

Legacy ID: #3571169 Legacy Poster: Thomas (tbliem)

Thanks, you guessed exactly what was happening!

RE: Removing processed processing instructions - Added by Anonymous over 17 years ago

Legacy ID: #3991363 Legacy Poster: CRA (samurai40k)

I have a related problem. I am modifying a pre-existing stylesheet that uses a for-each construct to transform the input data. What I want to do is explicitly copy any processing instructions that I come across in the for-each loop. Here is an edited portion of the data: <exp-level-1> <alias/> <heading> LATL-ARG ¶7000.01, <bold>Article 1--Personal scope </bold> </heading> <para> <bold> <search-segment>Article 1--Personal scope</search-segment> </bold> </para> <?UnOrderlist c:\Test\10-30-2006\arg01\arg01-Mod1-064.txt?> </exp-level-1> Here is an edited portion of the code: <xsl:for-each select="exp-level-1/*"> <xsl:choose> <xsl:when test="blah-x"> <xsl:value-of select="./text()"/> </xsl:when> <xsl:when test="blah-y"> <xsl:value-of select="./text()"/> </xsl:when> <xsl:when test="self::processing-instruction()"> <xsl:copy /> </xsl:when> </xsl:choose> </xsl:for-each> When I run the transform, I keep getting this error message: "The self axis will never select any element() nodes when starting at an processing-instruction() node" I have found many examples of this exact code usage while trying to find an answer to this problem, and I have tried several variations on it in order to try to fix it but I keep getting the same error. Am I missing something?

RE: Removing processed processing instruction - Added by Anonymous over 17 years ago

Legacy ID: #3991419 Legacy Poster: Michael Kay (mhkay)

The warning message means exactly what it says. The expression exp-level-1/* selects all element children of the exp-level-1 element. Within the body of the for-each the context item is therefore an element node; and therefore test="self::processing-instruction()" will never be true. I assume that what you really want is exp-level-1/node(). However, you really should be writing this using apply-templates, thus: <xsl:template match="/"> <xsl:apply-templates select="exp-level-1/child::node()"/> </xsl:template> <xsl:template match="blah-x"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="blah-y"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="processing-instruction()"> <xsl:copy/> </xsl:template>

RE: Removing processed processing instructions - Added by Anonymous over 17 years ago

Legacy ID: #3991503 Legacy Poster: CRA (samurai40k)

All I had to do was change the for-each from 'exp-level-1/*' to 'exp-level-1/node()' and the error went away and the processing instructions copied successfully. Thank you very much! Now I just have make sure that didn't have any negative repercussions elsewhere in other data.

    (1-5/5)

    Please register to reply