Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Ok so I have this xml file

   <?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>

and I'm trying to find a way to select rows. I can do it fine if they don't have the xsi namespace on them, but I can't figure out how to select with a namespace

Heres what I got for the 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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
396 views
Welcome To Ask or Share your Answers For Others

1 Answer

Add the namespace to your stylesheet.

<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'])"/>
   ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...