hi all,
sorry i am posting on top of this mail
i have a problem
see one xml file look like
<my-app>
<name></name>
<!--<class></class>-->
</my-app>
i want to uncomment the commented part through xslt. please help me
thanks in advance
hi all,
sorry i am posting on top of this mail
i have a problem
see one xml file look like
<my-app>
<name></name>
<!--<class></class>-->
</my-app>
i want to uncomment the commented part through xslt. please help me
thanks in advance
A robust way to turn commented XML fragments into real nodes is to parse the comment text and then decide whether to emit the parsed nodes. The quick trick shown earlier (emitting comment text with disable-output-escaping) can work for simple output, but it is fragile: it only affects serialization, does not produce real element nodes in the XSLT result tree, and many processors or APIs ignore it. For a reliable, testable transform use an XSLT processor that supports parsing strings as XML (XSLT 3.0 provides this).
Example (XSLT 3.0 idea): parse the comment into a fragment, extract the inner element name, test it against the existing filters, and only then copy the parsed nodes into the result. The core looks like this:
<xsl:template match="comment()">
<xsl:variable name="frag" select="parse-xml-fragment(.)"/>
<xsl:variable name="mappedName" select="$frag/*/filter-name/string()"/>
<xsl:if test="$mappedName = /my-app/filter/filter-name">
<xsl:copy-of select="$frag/*"/>
</xsl:if>
</xsl:template> Notes and cautions:
This approach lets the XSLT decide, per commented fragment, whether to “uncomment” it based on actual filter-name matches. It also produces a proper result tree suitable for further XSLT processing or accurate serialization. Thanks to for the original problem report and to @MartinHonnen for the guidance the thread received.
<!-- the identity template copies everything
(unless more specific templates apply) -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<!-- this template matches comments and uncomments them -->
<xsl:template match="comment()">
<xsl:value-of select="." disable-output-escaping="yes" />
</xsl:template>
hi all please help me i am very new in this
see i ahve one xml file ::
<my-app>
<filter>
<filter-name>myrunclass</filtername>
<filter-class>myFirstClass</filter-class>
</filter>
<filter>
<filter-name>myCompileclass</filtername>
<filter-class>mySecondClass</filter-class>
</filter>
<filter>
<filter-name>myclass</filtername>
<filter-class>myThirdClass</filter-class>
</filter>
<!--<filter-mapping>
<filter-name>myrunclass</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>-->
<filter-mapping>
<filter-name>ResponseEncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<!--<filter-mapping>
<filter-name>ResponseEncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>-->
</my-app>
i need to uncomment the filter-mapping tag but based on some condition like inside <filter> if <filter-name> tag is match with commented <filter-mapping>/<filter-name> tag then we need to uncomment only those <filter-mapping> tag.
so OUTPUT become like
<my-app>
<filter>
<filter-name>myrunclass</filtername>
<filter-class>myFirstClass</filter-class>
</filter>
<filter>
<filter-name>myCompileclass</filtername>
<filter-class>mySecondClass</filter-class>
</filter>
<filter>
<filter-name>myclass</filtername>
<filter-class>myThirdClass</filter-class>
</filter>
<filter-mapping>
<filter-name>myrunclass</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ResponseEncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<!--<filter-mapping>
<filter-name>ResponseEncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>-->
</my-app>
please help me
thanks in advance
hi all please help me i am very new in this
see i ahve one xml file ::<my-app>
<filter>
<filter-name>myrunclass</filtername>
<filter-class>myFirstClass</filter-class>
</filter>
<filter>
<filter-name>myCompileclass</filtername>
<filter-class>mySecondClass</filter-class>
</filter>
<filter>
<filter-name>myclass</filtername>
<filter-class>myThirdClass</filter-class>
</filter><!--<filter-mapping>
<filter-name>myrunclass</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>--><filter-mapping>
<filter-name>ResponseEncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping><!--<filter-mapping>
<filter-name>ResponseEncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>-->
</my-app>i need to uncomment the filter-mapping tag but based on some condition like inside <filter> if <filter-name> tag is match with commented <filter-mapping>/<filter-name> tag then we need to uncomment only those <filter-mapping> tag.
so OUTPUT become like
<my-app>
<filter>
<filter-name>myrunclass</filtername>
<filter-class>myFirstClass</filter-class>
</filter>
<filter>
<filter-name>myCompileclass</filtername>
<filter-class>mySecondClass</filter-class>
</filter>
<filter>
<filter-name>myclass</filtername>
<filter-class>myThirdClass</filter-class>
</filter><filter-mapping>
<filter-name>myrunclass</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping><filter-mapping>
<filter-name>ResponseEncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping><!--<filter-mapping>
<filter-name>ResponseEncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>-->
</my-app>please help me
thanks in advance
i got the answer thanks a lot of you people help and thanks to Mr. Martin Honnen who gave me the solution
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.