I am trying to get xsl comments on my XMLSpy XSLT output console, but the comment is not appearing. My xslt script is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:ota="http://www.opentravel.org/OTA/2003/05" exclude-result-prefixes="ota xsl">
	<xsl:output encoding="UTF-8" version="2.0" method="xml"/>
	<xsl:strip-space elements="*"/>
	<xsl:variable name="no_of_adult_persons" select="count(//ota:PassengerListItems/ota:PassengerListItem[@Code = '10'])"/>
	<xsl:variable name="adult_persons_prices">
		<xsl:call-template name="adult">
			<xsl:with-param name="nodelist_adult" select="//ota:PassengerListItems/ota:PassengerListItem[@Code = '10']"/>
			<xsl:with-param name="nodelist" select="//ota:CostingItem"/>
		</xsl:call-template>
	</xsl:variable>
	<xsl:template name="adult">
		<xsl:param name="nodelist_adult"/>
		<xsl:param name="nodelist"/>
		<xsl:param name="counter">1</xsl:param>
		<xsl:param name="sum">0.00</xsl:param>
		<xsl:variable name="rph" select="$nodelist_adult[$counter]/@RPH"/>

		<xsl:comment>
			<xsl:value-of select="count($nodelist_adult)"/>
		</xsl:comment>
		<xsl:comment>
			<xsl:value-of select="count($nodelist)"/>
		</xsl:comment>
		<xsl:comment>
			<xsl:value-of select="$counter"/>
		</xsl:comment>
		<xsl:comment>
			<xsl:value-of select="$sum"/>
		</xsl:comment>
		<xsl:comment>
			<xsl:value-of select="$nodelist_adult[$counter]/@RPH"/>
		</xsl:comment>
		<xsl:comment>=============================</xsl:comment>


		<xsl:variable name="sum_temp">
			<xsl:value-of select="$sum + $nodelist[$counter]/ota:UnitCost/@Amount"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$counter &lt; count($nodelist_adult)">
				<xsl:call-template name="adult">
					<xsl:with-param name="nodelist_adult" select="$nodelist_adult"/>
					<xsl:with-param name="nodelist" select="$nodelist"/>
					<xsl:with-param name="counter" select="$counter + 1"/>
					<xsl:with-param name="sum" select="$sum_temp"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$sum_temp"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>

and xml input

<?xml version="1.0" encoding="UTF-8"?>
<OTA_TT_PkgBookRS Version="1.0" xmlns="http://www.opentravel.org/OTA/2003/05">
	<Success/>
	<PackageReservation>
		<UniqueID ID="7305042" Type="14"/>
		<Package BrandCode="OHG" ProductCode="201842820" Status="Confirmed">
			<DateRange End="2011-05-10" Start="2011-04-26"/>
			<ItineraryItems>
				<ItineraryItem RPH="1" Status="Confirmed">
					<Accommodation>
						<Identity HotelCode="201842820" HotelName="Broncemar"/>
						<DateRange Duration="P14D" End="2011-05-10" Start="2011-04-26"/>
						<RoomProfiles>
							<RoomProfile BookingCode="201842820" RoomTypeCode="1011907">
								<GuestCounts IsPerRoom="true">
									<GuestCount AgeQualifyingCode="10" Count="2"/>
								</GuestCounts>
								<PassengerRPHs ListOfPassengerRPH="1 2"/>
							</RoomProfile>
						</RoomProfiles>
						<MealPlans>
							<MealPlan Code="BB" MealType="B &amp; B">
								<CustomerCounts>
									<CustomerCount Code="10" Quantity="2"/>
								</CustomerCounts>
								<PassengerRPHs ListOfPassengerRPH="1 2"/>
							</MealPlan>
						</MealPlans>
					</Accommodation>
				</ItineraryItem>
			</ItineraryItems>
		</Package>
		<ContactDetail>
			<PersonName>
				<NamePrefix>Mr</NamePrefix>
				<GivenName>Mark</GivenName>
				<Surname>Dost</Surname>
			</PersonName>
			<Telephone PhoneNumber="02349711464"/>
			<Address>
				<StreetNmbr>Unistr.90</StreetNmbr>
				<CityName>Bochum</CityName>
				<PostalCode>44789</PostalCode>
				<CountryName Code="DE">Deutschland</CountryName>
			</Address>
			<Email>mark.dost@iff.traveltainment.de</Email>
		</ContactDetail>
		<PassengerListItems>
			<PassengerListItem BirthDate="1986-01-12" Code="10" Gender="Male" RPH="1">
				<Name>
					<NamePrefix>Mr</NamePrefix>
					<GivenName>Mark</GivenName>
					<Surname>Dost</Surname>
				</Name>
			</PassengerListItem>
			<PassengerListItem BirthDate="1987-01-12" Code="10" Gender="Female" RPH="2">
				<Name>
					<NamePrefix>Mrs</NamePrefix>
					<GivenName>Claudia</GivenName>
					<Surname>Ollmann</Surname>
				</Name>
			</PassengerListItem>
		</PassengerListItems>
		<InvoiceDetail>
			<CostingItems>
				<CostingItem CostBasis="7" PassengerRPH="1">
					<UnitCost Amount="398.01" CurrencyCode="EUR"/>
				</CostingItem>
				<CostingItem CostBasis="7" PassengerRPH="2">
					<UnitCost Amount="57.5000" CurrencyCode="EUR"/>
				</CostingItem>
			</CostingItems>
			<GrossAmount Amount="455.51" CurrencyCode="EUR"/>
		</InvoiceDetail>
	</PackageReservation>
</OTA_TT_PkgBookRS>

Could someone please help me out?

I am using xslt 1.0 xalan processor in my xmlspy

Dani AI

Generated

Short answer: xsl:comment creates comment nodes in the result tree. If those comment nodes are never part of the final serialized output (for example because they were built inside a result-tree-fragment stored in a variable and never copied into the result), or if your viewer hides comment nodes, you will not see them. The posted stylesheet shows the template producing comments while its output is captured in a variable, so the comments are likely never serialized.

What to try (quick checklist)

  • Verify a comment that is definitely in the final result. Put a comment directly under your root output element or copy the fragment into the output and check the serialized/text output (tree/grid views sometimes hide comments).
  • For one-off debugging, use xsl:message (it goes to the processor/message console and does not depend on the serialized result):
<xsl:message terminate="no">
  <xsl:text>DEBUG: adults = </xsl:text>
  <xsl:value-of select="count(//ota:PassengerListItem)"/>
</xsl:message>
  • If the comments were created inside an xsl:variable (a result-tree-fragment), output them explicitly with copy-of so comment nodes are written out:
<xsl:copy-of select="$yourResultFragment"/>

Notes and pitfalls

  • A raw stylesheet comment (<!-- ... -->) lives in the stylesheet source and will not appear in the transformation result; use xsl:comment to create result comments.
  • Using xsl:value-of on an RTF returns text only (comments are lost); xsl:copy-of preserves comment nodes.
  • If you need to inspect or iterate nodes inside a result-tree-fragment, convert it to a node-set with your processor’s node-set extension (EXSLT or the processor-specific function) before using XPath functions on it.
  • Prefer xsl:message for debugging because it’s visible even when comments would be hidden by the viewer.

Links to earlier replies: was right to point out literal comments vs. output, and is correct that xsl:comment is the mechanism to create comments — the important bit is to place or serialize those comment nodes where the output viewer can show them.

Recommended Answers

All 2 Replies

you can put in comments like this.

<!-- desired comment here -->

if you want it to actually show on the conversion it csn be done with <xsl:text> content here </xsl:text>

For XSL Comment use Below Syntax

<xsl:comment>

<!-- Content:template -->

</xsl:comment>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.