我有一个场景,当我需要从 server.xml (tomcat) 中取消注释 SSL 配置并且还需要在其中添加几个属性时。当 SSL 配置已经可用但我的模板不适用于刚刚未注释的部分时,我成功添加了两个属性。任何的想法?
<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet type="text/xsl" href="new2.xsl"?>
<Server port="8005" shutdown="SHUTDOWN">
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<Connector port="8080" URIEncoding="UTF-8" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!--NEED TO UNCOMMENT AND ADD ATTRIBUTES IN THE FOLLOWING ELEMENT-->
<!--<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" /> -->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
</Engine>
</Service>
</Server>
xslt 紧随其后,取消注释该部分,如果该部分已取消注释,则在其中添加两个属性。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()" name="Copy">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | node()" mode="insertConnector">
<xsl:call-template name="Copy" />
</xsl:template>
<!--If the SSL configuration doesn't exist but availabe in comments, uncomment it-->
<xsl:template match="comment()[not(../Connector[@scheme = 'https']) and
contains(., 'Connector') and
(contains(., 'scheme=https') or
contains(., scheme='https'))]">
<xsl:value-of select="." disable-output-escaping="yes"/> <!--This line uncomments the comment-->
</xsl:template>
<xsl:template match = "Connector[@scheme = 'https']" name="AddAttributes">
<Connector keystoreFile="${user.home}/.keystore">
<xsl:apply-templates select="@* | node()"/>
</Connector>
</xsl:template>
</xsl:stylesheet>
请指导我如何在注释部分添加属性或在取消注释后立即在元素中添加属性。以上 XSLT 只是取消注释 SSL 配置部分。谢谢你。