Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to comment out the results of XSL:COPY-OF in a XSL file...help 2

Status
Not open for further replies.

tektipsjunkie

Programmer
Dec 2, 2009
6
US
I am transforming an XML doc from Schema A to Schema B. These are two established standards, Schema A being newer. Schema A actually has more built in elements and can house more detailed information than Schema B, which is fine. THey try to describe the same thing. however, to not lose data I would like the copy the entire contents of the XML doc in Schema A format to an XML doc in schema B format, after the schema B requirements have been met in the translation. Meaning, I take Schema A info and format it for schema B info in the output, THEN take entire contents (xsl:copy-of select="$varRoot") of schema A place it in schema A format in the output doc, again after the schema B format. Clear as mud? When I did this, I obviously couldn't validate. So I want to comment out the schema A section of the output. How do I do this? I am using XSL:COPY-OF and it works but I would like to place it results in comments in the output. Everything I've tried has commented out the XSL:COPY-OF. Help.
 
I guess I'm looking for an echo type command that would allow xsl:copy-of to run but comment out the output.

echo "<!--"
<xsl:copy-of select="$varRoot"></xsl:copy-of>
echo "-->"

How do you pull off the "echo" in XSL?

My desired result...

<!--
<ms:Resource attribute1="asdf" attibute2="qwerty" etc... </ms:Resource>
-->

Help
 
Currently it not looking like it can be done. I got the comments in the output, but the way the html comments work, if there is any comment at all being copied over, the --> will stop all previous <!--. Does anybody have a solution? Please help!

Greg
 
This is what I use
Code:
    <xsl:text disable-output-escaping="yes">
<!--
</xsl:text>
    <xsl:copy-of select="descendant::node()[position()>2]"/>
    <xsl:text disable-output-escaping="yes">
-->
</xsl:text>
 
Follow on to previous post ...

Looks like this forum mangles XML encodings even though I placed them within code blocks. Use "& # 6 0 ; ! - - ", without the spaces, for start of comment and " - - & # 6 2 ;", without the spaces, for end of comment.


 
I ended up using CDATA instead. Broke it up in the text element like you did, and it worked. Thanks
 
<xsl:text disable-output-escaping="yes">&lt;</xsl:text><xsl:text disable-output-escaping="yes">![CDATA["</xsl:text>
<xsl:copy-of select="$varRoot" ></xsl:copy-of>
<xsl:text disable-output-escaping="yes">"]]</xsl:text><xsl:text disable-output-escaping="yes">&gt;</xsl:text>

This is what I did. The <!-- --> would stop if there were any other comments in the contents of $varRoot. I was copying over about 150 lines of XML under one element. Thanks.
 
[1] Since comment cannot be nested, the approach(es) posted, though is of limited scope of applicability and do reasonably well in that regard, in most cases, it is unfortunately not very "suitable".

[2] Copying the original xml commented out into the new xml: thinking of it is not really very attractive objective. It is an issue of document management and should be treated as such: not exploding the new document's size when everybody, who is not completely friendly with xml technology, is complaining xml being verbose.

[3] If you want to preserve the original document into the new document of new schema, the simplest approach without losing any information (including comments), except perhaps the prolog, is to provision a special tag in the schema B, say something like <ns:documentation> in some appropriate namespace ns, in the schema B, so that ns:documentation is of xs:any type with lax processing with any attributes as well, if so desired. (It is very important when "commented", no information is lost, including delinquent namespaces which are not available ready to be reversed to recover the original.) In that case, you can simply use copy-of inside that element.
[tt]
<ns:documentation src="some-uri-or-other-specificity">
<xsl:copy-of select="$varRoot" />
<ns:documentation>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top