Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xslt和xml名称空间和属性_Xml_Xslt - Fatal编程技术网

xslt和xml名称空间和属性

xslt和xml名称空间和属性,xml,xslt,Xml,Xslt,好的,我有这个xml文件 <?xml version="1.0" encoding="us-ascii"?> <?xml-stylesheet type="text/xsl" href="logstyle.xslt"?> <Events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ConsoleEvent> <message>Setting

好的,我有这个xml文件

   <?xml version="1.0" encoding="us-ascii"?>
<?xml-stylesheet type="text/xsl" href="logstyle.xslt"?>
<Events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ConsoleEvent>
        <message>Settings file loaded.</message>
        <date>2011-02-24T02:49:21.9063187-06:00</date>
    </ConsoleEvent>
    <ConsoleEvent type="ConsoleEventError">
        <message>Invalid command 'lol'.</message>
        <date>2011-02-24T02:49:23.9734369-06:00</date>
        <ExceptionMessage>Invalid console command.</ExceptionMessage>
        <StackTrace>No Stack Trace Message Data.</StackTrace>
    </ConsoleEvent>
    <ConsoleEvent xsi:type="ConsoleEventError">
        <message>Invalid command 'yo'.</message>
        <date>2011-02-24T02:49:24.9124907-06:00</date>
        <ExceptionMessage>Invalid console command.</ExceptionMessage>
        <StackTrace>No Stack Trace Message Data.</StackTrace>
    </ConsoleEvent>
    <ConsoleEvent xsi:type="ConsoleEventError">
        <message>Invalid command 'hello'.</message>
        <date>2011-02-24T02:49:25.9915524-06:00</date>
        <ExceptionMessage>Invalid console command.</ExceptionMessage>
        <StackTrace>No Stack Trace Message Data.</StackTrace>
    </ConsoleEvent>
    <ConsoleEvent>
        <message>Baking args brah...
</message>
        <date>2011-02-24T02:49:28.1296747-06:00</date>
    </ConsoleEvent>
    <ConsoleEvent>
        <message>Baking args brah...
b = vag 
a = gav
</message>
        <date>2011-02-24T02:49:38.7152801-06:00</date>
    </ConsoleEvent>
    <ConsoleEvent>
        <message>Quitting...</message>
        <date>2011-02-24T02:49:39.8563454-06:00</date>
    </ConsoleEvent>
</Events>

已加载设置文件。
2011-02-24T02:49:21.9063187-06:00
无效命令“lol”。
2011-02-24T02:49:23.9734369-06:00
无效的控制台命令。
没有堆栈跟踪消息数据。
无效命令“yo”。
2011-02-24T02:49:24.9124907-06:00
无效的控制台命令。
没有堆栈跟踪消息数据。
无效的命令“hello”。
2011-02-24T02:49:25.9915524-06:00
无效的控制台命令。
没有堆栈跟踪消息数据。
烤阿格斯布拉。。。
2011-02-24T02:49:28.1296747-06:00
烤阿格斯布拉。。。
b=阴道
a=gav
2011-02-24T02:49:38.7152801-06:00
退出。。。
2011-02-24T02:49:39.8563454-06:00
我正试图找到一种选择行的方法。如果他们没有xsi名称空间,我可以做得很好,但我不知道如何使用名称空间进行选择

这是我为xsi得到的

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
  <xsl:output method="html"  encoding="utf-16"/>
  <xsl:template match="Events">
    <head>
      <title>Event Log</title>
      <style type="text/css">
        body{ text-align: left; width: 100%;  font-family: Verdana, sans-serif; }

        table{ border: none;  border-collapse: separate;  width: 100%; }

        tr.title td{ font-size: 24px;  font-weight: bold; }

        th{ background: #d0d0d0;  font-weight: bold;  font-size: 10pt;  text-align: left; }
        tr{ background: #eeeeee}
        td, th{ font-size: 8pt;  padding: 1px;  border: none; }

        tr.info td{}
        tr.warning td{background-color:yellow;color:black}
        tr.error td{background-color:red;color:black}

        span {text-decoration:underline}
        a:hover{text-transform:uppercase;color: #9090F0;}
      </style>
    </head>

    <body>
      <table>
        <tr class="title">
          <td colspan="7">Event Log</td>
        </tr>
        <tr>
          <td colspan="2">Standard Events</td>
          <td colspan="5">
            <xsl:value-of select="count(//ConsoleEvent)"/>
          </td>
        </tr>
        <tr>
          <td colspan="2">Errors</td>
          <td colspan="5">
            <xsl:value-of select="count(//ConsoleEvent[@type='ConsoleEventError'])"/>
          </td>
        </tr>
        <xsl:apply-templates/>
      </table>

    </body>
  </xsl:template>

</xsl:stylesheet>

事件日志
正文{文本对齐:左;宽度:100%;字体系列:Verdana,无衬线;}
表{边框:无;边框折叠:单独;宽度:100%;}
tr.title td{font size:24px;font-weight:bold;}
th{背景:#d0d0;字体大小:粗体;字体大小:10pt;文本对齐:左;}
tr{背景:#eeeeee}
td,th{font size:8pt;padding:1px;border:none;}
tr.info td{}
tr.warning td{背景色:黄色;颜色:黑色}
tr.error td{背景色:红色;颜色:黑色}
span{文本装饰:下划线}
a:悬停{文本转换:大写;颜色:#9090F0;}
事件日志
标准事件
错误

将名称空间添加到样式表中

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   ...
            <xsl:value-of select="count(//ConsoleEvent[@xsi:type='ConsoleEventError'])"/>
   ...

...
...

将名称空间添加到样式表中

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   ...
            <xsl:value-of select="count(//ConsoleEvent[@xsi:type='ConsoleEventError'])"/>
   ...

...
...
解决方案(这次记住规则!)

  • xsi名称空间
    定义
    添加到XSLT样式表中:

  • 相应地更改代码

            <tr>
                <td colspan="2">Errors</td>
                <td colspan="5">
                    <xsl:value-of select=
                    "count(//ConsoleEvent
                              [@type='ConsoleEventError'
                             or
                               @xsi:type='ConsoleEventError'
                              ]
                          )"/>
                </td>
            </tr>
    
    
    错误
    
  • 您的整个代码变为

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    exclude-result-prefixes="xsi">
        <xsl:output method="html"  encoding="utf-16"/>
        <xsl:template match="Events">
            <head>
                <title>Event Log</title>
                <style type="text/css">
                   body{ text-align: left; width: 100%;  font-family: Verdana, sans-serif; }          table{ border: none;  border-collapse: separate;  width: 100%; }          tr.title td{ font-size: 24px;  font-weight: bold; }          th{ background: #d0d0d0;  font-weight: bold;  font-size: 10pt;  text-align: left; }         tr{ background: #eeeeee}         td, th{ font-size: 8pt;  padding: 1px;  border: none; }          tr.info td{}         tr.warning td{background-color:yellow;color:black}         tr.error td{background-color:red;color:black}          span {text-decoration:underline}         a:hover{text-transform:uppercase;color: #9090F0;}       </style>
            </head>
            <body>
                <table>
                    <tr class="title">
                        <td colspan="7">Event Log</td>
                    </tr>
                    <tr>
                        <td colspan="2">Standard Events</td>
                        <td colspan="5">
                            <xsl:value-of select="count(//ConsoleEvent)"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">Errors</td>
                        <td colspan="5">
                            <xsl:value-of select=
                            "count(//ConsoleEvent
                                      [@type='ConsoleEventError'
                                     or
                                       @xsi:type='ConsoleEventError'
                                      ]
                       )"/>
                        </td>
                    </tr>
                    <xsl:apply-templates/>
                </table>
            </body>
        </xsl:template>
    </xsl:stylesheet>
    
    <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-16">
    
       <title>Event Log</title><style type="text/css">
                   body{ text-align: left; width: 100%;  font-family: Verdana, sans-serif; }          table{ border: none;  border-collapse: separate;  width: 100%; }          tr.title td{ font-size: 24px;  font-weight: bold; }          th{ background: #d0d0d0;  font-weight: bold;  font-size: 10pt;  text-align: left; }         tr{ background: #eeeeee}         td, th{ font-size: 8pt;  padding: 1px;  border: none; }          tr.info td{}         tr.warning td{background-color:yellow;color:black}         tr.error td{background-color:red;color:black}          span {text-decoration:underline}         a:hover{text-transform:uppercase;color: #9090F0;}       </style></head>
    <body>
       <table>
          <tr class="title">
             <td colspan="7">Event Log</td>
          </tr>
          <tr>
             <td colspan="2">Standard Events</td>
             <td colspan="5">7</td>
          </tr>
          <tr>
             <td colspan="2">Errors</td>
             <td colspan="5">3</td>
          </tr>
    
                Settings file loaded.
                2011-02-24T02:49:21.9063187-06:00
    
    
                Invalid command 'lol'.
                2011-02-24T02:49:23.9734369-06:00
                Invalid console command.
                No Stack Trace Message Data.
    
    
                Invalid command 'yo'.
                2011-02-24T02:49:24.9124907-06:00
                Invalid console command.
                No Stack Trace Message Data.
    
    
                Invalid command 'hello'.
                2011-02-24T02:49:25.9915524-06:00
                Invalid console command.
                No Stack Trace Message Data.
    
    
                Baking args brah... 
                2011-02-24T02:49:28.1296747-06:00
    
    
                Baking args brah... b = vag  a = gav 
                2011-02-24T02:49:38.7152801-06:00
    
    
                Quitting...
                2011-02-24T02:49:39.8563454-06:00
    
    
       </table>
    </body>
    
    
    事件日志
    正文{文本对齐:左;宽度:100%;字体系列:Verdana,无衬线;}表格{边框:无;边框折叠:分开;宽度:100%;}tr.title td{字体大小:24px;字体重量:粗体;}th{背景:#d0d0d0;字体重量:粗体;字体大小:10pt;文本对齐:左;}tr tr{背景:#eeeeee}td,th{font size:8pt;padding:1px;border:none;}tr.info td{}tr.warning td{background color:yellow;color:black}tr.error td{background color:red;color:black}span{文本装饰:下划线}a:hover{文本转换:大写;color:#9090F0;}
    事件日志
    标准事件
    错误
    
    您将得到正确的结果

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    exclude-result-prefixes="xsi">
        <xsl:output method="html"  encoding="utf-16"/>
        <xsl:template match="Events">
            <head>
                <title>Event Log</title>
                <style type="text/css">
                   body{ text-align: left; width: 100%;  font-family: Verdana, sans-serif; }          table{ border: none;  border-collapse: separate;  width: 100%; }          tr.title td{ font-size: 24px;  font-weight: bold; }          th{ background: #d0d0d0;  font-weight: bold;  font-size: 10pt;  text-align: left; }         tr{ background: #eeeeee}         td, th{ font-size: 8pt;  padding: 1px;  border: none; }          tr.info td{}         tr.warning td{background-color:yellow;color:black}         tr.error td{background-color:red;color:black}          span {text-decoration:underline}         a:hover{text-transform:uppercase;color: #9090F0;}       </style>
            </head>
            <body>
                <table>
                    <tr class="title">
                        <td colspan="7">Event Log</td>
                    </tr>
                    <tr>
                        <td colspan="2">Standard Events</td>
                        <td colspan="5">
                            <xsl:value-of select="count(//ConsoleEvent)"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">Errors</td>
                        <td colspan="5">
                            <xsl:value-of select=
                            "count(//ConsoleEvent
                                      [@type='ConsoleEventError'
                                     or
                                       @xsi:type='ConsoleEventError'
                                      ]
                       )"/>
                        </td>
                    </tr>
                    <xsl:apply-templates/>
                </table>
            </body>
        </xsl:template>
    </xsl:stylesheet>
    
    <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-16">
    
       <title>Event Log</title><style type="text/css">
                   body{ text-align: left; width: 100%;  font-family: Verdana, sans-serif; }          table{ border: none;  border-collapse: separate;  width: 100%; }          tr.title td{ font-size: 24px;  font-weight: bold; }          th{ background: #d0d0d0;  font-weight: bold;  font-size: 10pt;  text-align: left; }         tr{ background: #eeeeee}         td, th{ font-size: 8pt;  padding: 1px;  border: none; }          tr.info td{}         tr.warning td{background-color:yellow;color:black}         tr.error td{background-color:red;color:black}          span {text-decoration:underline}         a:hover{text-transform:uppercase;color: #9090F0;}       </style></head>
    <body>
       <table>
          <tr class="title">
             <td colspan="7">Event Log</td>
          </tr>
          <tr>
             <td colspan="2">Standard Events</td>
             <td colspan="5">7</td>
          </tr>
          <tr>
             <td colspan="2">Errors</td>
             <td colspan="5">3</td>
          </tr>
    
                Settings file loaded.
                2011-02-24T02:49:21.9063187-06:00
    
    
                Invalid command 'lol'.
                2011-02-24T02:49:23.9734369-06:00
                Invalid console command.
                No Stack Trace Message Data.
    
    
                Invalid command 'yo'.
                2011-02-24T02:49:24.9124907-06:00
                Invalid console command.
                No Stack Trace Message Data.
    
    
                Invalid command 'hello'.
                2011-02-24T02:49:25.9915524-06:00
                Invalid console command.
                No Stack Trace Message Data.
    
    
                Baking args brah... 
                2011-02-24T02:49:28.1296747-06:00
    
    
                Baking args brah... b = vag  a = gav 
                2011-02-24T02:49:38.7152801-06:00
    
    
                Quitting...
                2011-02-24T02:49:39.8563454-06:00
    
    
       </table>
    </body>
    
    
    事件日志
    正文{文本对齐:左;宽度:100%;字体系列:Verdana,无衬线;}表格{边框:无;边框折叠:分开;宽度:100%;}tr.title td{字体大小:24px;字体重量:粗体;}th{背景:#d0d0d0;字体重量:粗体;字体大小:10pt;文本对齐:左;}tr tr{背景:#eeeeee}td,th{font size:8pt;padding:1px;border:none;}tr.info td{}tr.warning td{background color:yellow;color:black}tr.error td{background color:red;color:black}span{文本装饰:下划线}a:hover{文本转换:大写;color:#9090F0;}
    事件日志
    标准事件
    7.
    错误
    3.
    已加载设置文件。
    2011-02-24T02:49:21.9063187-06:00
    无效命令“lol”。
    2011-02-24T02:49:23.9734369-06:00
    无效的控制台命令。
    没有堆栈跟踪消息数据。
    无效命令“yo”。
    2011-02-24T02:49:24.9124907-06:00
    无效的控制台命令。
    没有堆栈跟踪消息数据。
    无效的命令“hello”。
    2011-02-24T02:49:25.9915524-06:00
    无效的控制台命令。
    没有堆栈跟踪消息数据。
    烤阿格斯布拉。。。
    2011-02-24T02:49:28.1296747-06:00
    烘焙参数brah…b=vag a=gav
    2011-02-24T02:49:38.7152801-06:00
    退出。。。
    2011-02-24T02:49:39.8563454-06:00
    
    解决方案(这次记住规则!)

  • xsi名称空间
    定义
    添加到XSLT样式表中:

  • 相应地更改代码

            <tr>
                <td colspan="2">Errors</td>
                <td colspan="5">
                    <xsl:value-of select=
                    "count(//ConsoleEvent
                              [@type='ConsoleEventError'
                             or
                               @xsi:type='ConsoleEventError'
                              ]
                          )"/>
                </td>
            </tr>
    
    
    错误
    
  • 您的整个代码变为

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    exclude-result-prefixes="xsi">
        <xsl:output method="html"  encoding="utf-16"/>
        <xsl:template match="Events">
            <head>
                <title>Event Log</title>
                <style type="text/css">
                   body{ text-align: left; width: 100%;  font-family: Verdana, sans-serif; }          table{ border: none;  border-collapse: separate;  width: 100%; }          tr.title td{ font-size: 24px;  font-weight: bold; }          th{ background: #d0d0d0;  font-weight: bold;  font-size: 10pt;  text-align: left; }         tr{ background: #eeeeee}         td, th{ font-size: 8pt;  padding: 1px;  border: none; }          tr.info td{}         tr.warning td{background-color:yellow;color:black}         tr.error td{background-color:red;color:black}          span {text-decoration:underline}         a:hover{text-transform:uppercase;color: #9090F0;}       </style>
            </head>
            <body>
                <table>
                    <tr class="title">
                        <td colspan="7">Event Log</td>
                    </tr>
                    <tr>
                        <td colspan="2">Standard Events</td>
                        <td colspan="5">
                            <xsl:value-of select="count(//ConsoleEvent)"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">Errors</td>
                        <td colspan="5">
                            <xsl:value-of select=
                            "count(//ConsoleEvent
                                      [@type='ConsoleEventError'
                                     or
                                       @xsi:type='ConsoleEventError'
                                      ]
                       )"/>
                        </td>
                    </tr>
                    <xsl:apply-templates/>
                </table>
            </body>
        </xsl:template>
    </xsl:stylesheet>
    
    <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-16">
    
       <title>Event Log</title><style type="text/css">
                   body{ text-align: left; width: 100%;  font-family: Verdana, sans-serif; }          table{ border: none;  border-collapse: separate;  width: 100%; }          tr.title td{ font-size: 24px;  font-weight: bold; }          th{ background: #d0d0d0;  font-weight: bold;  font-size: 10pt;  text-align: left; }         tr{ background: #eeeeee}         td, th{ font-size: 8pt;  padding: 1px;  border: none; }          tr.info td{}         tr.warning td{background-color:yellow;color:black}         tr.error td{background-color:red;color:black}          span {text-decoration:underline}         a:hover{text-transform:uppercase;color: #9090F0;}       </style></head>
    <body>
       <table>
          <tr class="title">
             <td colspan="7">Event Log</td>
          </tr>
          <tr>
             <td colspan="2">Standard Events</td>
             <td colspan="5">7</td>
          </tr>
          <tr>
             <td colspan="2">Errors</td>
             <td colspan="5">3</td>
          </tr>
    
                Settings file loaded.
                2011-02-24T02:49:21.9063187-06:00
    
    
                Invalid command 'lol'.
                2011-02-24T02:49:23.9734369-06:00
                Invalid console command.
                No Stack Trace Message Data.
    
    
                Invalid command 'yo'.
                2011-02-24T02:49:24.9124907-06:00
                Invalid console command.
                No Stack Trace Message Data.
    
    
                Invalid command 'hello'.
                2011-02-24T02:49:25.9915524-06:00
                Invalid console command.
                No Stack Trace Message Data.
    
    
                Baking args brah... 
                2011-02-24T02:49:28.1296747-06:00
    
    
                Baking args brah... b = vag  a = gav 
                2011-02-24T02:49:38.7152801-06:00
    
    
                Quitting...
                2011-02-24T02:49:39.8563454-06:00
    
    
       </table>
    </body>
    
    
    事件日志
    正文{文本对齐:左;宽度:100%;字体系列:Verdana,无衬线;}表格{边框:无;边框折叠:分隔;宽度:100%;}tr.title td{f