如何匹配在另一个序列中具有所有节点的节点

时间:2015-07-29 04:48:54

标签: xslt xpath

我们正在使用 XSLT2 。想知道这是否可能。

我们有一个标记过滤器,客户可以选择查看与其选择所有匹配的所有主题。

以下是XML结构的概念:

<themes>
   <theme>
      <name>Apple</name>
      <tags>
         <tag id="1">
         <tag id="2">
      </tags>
   </theme>
   <theme>
      <name>Banana</name>
      <tags>
         <tag id="2">
         <tag id="3">
      </tags>
   </theme>
   <theme>
      <name>Kiwifruit</name>
      <tags>
         <tag id="2">
         <tag id="3">
      </tags>
   </theme>
</themes>

客户选择标签2和3.我们想要的结果是只显示Banana和Kiwifruit,因为它们具有用户选择的所有标签。

我们不能使用AND运算符,因为标签列表很长且未知。我们目前将此列表传递给XSLT,然后进行标记:

<xsl:param name="tag_ids"/>   
<xsl:variable name="tag_id_list" select="tokenize($tag_ids,',')"/>

此语句选择任何具有任何tag_id_list的主题:

<xsl:for-each select="themes/theme/tags/tag[@id=$tag_id_list]">

但我们正试图找到一个XPath语句,确保在$ tag_id_list中包含所有s

任何想法?!提前谢谢。

2 个答案:

答案 0 :(得分:4)

如果标签必须采用正确的顺序,您需要这样做:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

        <property name="connection.url">jdbc:mysql://localhost:3306/mahlzeit_db</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Batch size -->
        <!-- <property name="hibernate.jdbc.batch_size">20</property> -->

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">false</property>
        <property name="format_sql">false</property>

        <!-- Drop and re-create the database schema on startup -->
        <!-- <property name="hibernate.hbm2ddl.auto">create-drop</property> -->
        <!-- Run Hibernate in update mode -->
        <property name="hibernate.hbm2ddl.auto">update</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
        <!-- Bind the getCurrentSession() method to the thread -->
        <!-- <property name="current_session_context_class">thread</property> -->

        <!-- Mappings ... -->

    </session-factory>

</hibernate-configuration>

或者如果它们可以按任何顺序排列:

com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.util.List com.mahlzeit.web.shared.service.restaurant.RestaurantInformationService.getAvailableRestaurants()' threw an unexpected exception: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
        at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:415)
        at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:605)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:333)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:303)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:373)
        at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:126)
        at org.hibernate.internal.AbstractSessionImpl.getJdbcConnectionAccess(AbstractSessionImpl.java:261)
        at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.<init>(JdbcCoordinatorImpl.java:97)
        at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.<init>(TransactionCoordinatorImpl.java:87)
        at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:254)
        at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1609)
        at org.hibernate.internal.SessionFactoryImpl.openSession(SessionFactoryImpl.java:973)
        at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:122)
        at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:988)
        at com.mahlzeit.web.server.dao.RestaurantOwnerRepository.getAvailableRestaurants(RestaurantOwnerRepository.java:62)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:266)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
        at com.sun.proxy.$Proxy50.getAvailableRestaurants(Unknown Source)
        at com.mahlzeit.web.server.service.restaurant.RestaurantInformationServiceImpl.getAvailableRestaurants(RestaurantInformationServiceImpl.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:587)
        ... 25 more

答案 1 :(得分:1)

您可以计算匹配的代码数量,并查看它是否等于str_replace('+00:00', 'Z', $date->toString(Zend_Date::ISO_8601))中的代码数量。例如

<Assets>
    <Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>

如果客户可以输入重复的标签(例如“2,2,3”),那么您可能需要将tag_id_list更改为此

    <xsl:variable name="tagcount" select="count($tag_id_list)" />
    <xsl:for-each select="themes/theme[count(tags/tag[@id=$tag_id_list]) = $tagcount]">