开发者

using xslt how do i address this particular element in an xml file?

Never coded for XML before, totally lost with the various primers which all tell me to do something different. Which probably means you can do it different ways, but they all show single node situations and this isn't.

I've tried various ways to pick out the WebDisplayPeriod but im convinced im not actually targetting the attribute of that one right. Would love someone to give me a push in the right direction please. also any readable primers on more advanced use of XSLT would be appreciated as w3schools is rubbish ;) .

I've got the following xml

<?xml version="1.0" encoding="UTF-8"?>
<nr:RTPPMDataMsgV1 owner="Network Rail" timestamp="2010-08-05T10:27:04.0Z" classification="public" xsi:schemaLocation="http://xml.networkrail.co.uk/ns/2007/NR rtppm_messaging_v1.17.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:msg="http://xml.networkrail.co.uk/ns/2007/EAI" xmlns:nr="http://xml.networkrail.co.uk/ns/2007/NR">
 <msg:Sender application="RTPPM3" organisation="String"/>
  <msg:Publication>
  <msg:TopicID>RTPPM3/InternalPPM</msg:TopicID>
 </msg:Publication>
 <nr:RTPPMData snapshotTStamp="2010-08-05T10:27:02.0Z">
  <nr:SystemMsg/>
  <nr:RAGThresholds type="TOC" medium="87" good="92"/>
  <nr:RAGThresholds type="FOC" medium="70" good="80"/>
  <nr:RAGThresholds type="PPT" medium="85" good="91"/>
  <nr:WebPPMLink>http://connect/Performance/PPM/PPMGuide.doc x</nr:WebPPMLink>
   <nr:PPT rag="G" ragDisplayFlag="Y">93</nr:PPT>
 <nr:NationalPage WebDisplayPeriod="60">
  <nr:WebFixedMsg1>^&lt;5 mins; *&lt;10 mins</nr:WebFixedMsg1>
    <开发者_StackOverflow中文版;nr:WebFixedMsg2>The Public Performance Measure shows the performance of trains against the timetable, measured as the percentage of trains arriving at destination &apos;on time&apos;. </nr:WebFixedMsg2>
    <nr:WebMsgOfMoment>EC: 1S02 train defect at Balne.</nr:WebMsgOfMoment>
    <nr:StaleFlag>N</nr:StaleFlag>
    <nr:NationalPPM>
    <nr:Total>5079</nr:Total>
    <nr:OnTime>4842</nr:OnTime>
    <nr:Late>237</nr:Late>
    <nr:CancelVeryLate>47</nr:CancelVeryLate>
    <nr:PPM rag="G" ragDisplayFlag="N">95</nr:PPM>
    <nr:RollingPPM trendInd="-" rag="G">94</nr:RollingPPM>
  </nr:NationalPPM>
......

it goes on and on. but the bit im interested in is in the section above.

I'm using the following XSLT to turn it into a legible webpage:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xsi:schemaLocation="http://xml.networkrail.co.uk/ns/2007/NR rtppm_messaging_v1.6.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:msg="http://xml.networkrail.co.uk/ns/2007/EAI" xmlns:nr="http://xml.networkrail.co.uk/ns/2007/NR"  >
<xsl:output method="html" omit-xml-declaration="yes" indent="yes" />

<xsl:param name="mode">TOCPage</xsl:param>
<xsl:param name="location">internal-connect</xsl:param>
<xsl:param name="table1Count">11</xsl:param>
<xsl:param name="table2Count">23</xsl:param>

    <!-- Root template--> 
    <xsl:template match="/nr:RTPPMDataMsgV1/nr:RTPPMData">
        <xsl:element name="{nr:NationalPage}">
            <xsl:attribute name="{WebDisplayPeriod}" >
                <xsl:value-of select="."/>
            </xsl:attribute>
         </xsl:element>
 <html>
<head>
<meta http-equiv="content-type" CONTENT="text/css" />
<meta http-equiv="expires" CONTENT="-1" />
<meta http-equiv="pragma" CONTENT="no-cache" />
<meta http-equiv="cache-control" CONTENT="no-cache" />
<meta http-equiv="refresh" name="refresh" content="{$WebDisplayPeriod}" />
 <title>EC RTPPM Feed</title>
 <link rel="stylesheet" type="text/css" href="stylesheet.css" />
 <link rel="stylesheet" type="text/css" href="xslstylesheet.css" />
</head>

<body>
<p>Hello</p>
      <p>Hello</p>
</body>
</html>
</xsl:template >
</xsl:stylesheet>

and as youve guessed, it never picks up the WebDisplayPeriod.


Try it something like this:

<xsl:template match="/nr:RTPPMDataMsgV1/nr:RTPPMData">
  <xsl:variable name="WebDisplayPeriod" select="./nr:NationalPage/@WebDisplayPeriod" />

 <html>
<head>
<meta http-equiv="content-type" CONTENT="text/css" />
<meta http-equiv="expires" CONTENT="-1" />
<meta http-equiv="pragma" CONTENT="no-cache" />
<meta http-equiv="cache-control" CONTENT="no-cache" />
<meta http-equiv="refresh" name="refresh" content="{$WebDisplayPeriod}" />
 <title>EC RTPPM Feed</title>
 <link rel="stylesheet" type="text/css" href="stylesheet.css" />
 <link rel="stylesheet" type="text/css" href="xslstylesheet.css" />
</head>

<body>
<p>Hello</p>
      <p>Hello</p>
</body>
</html>
</xsl:template >


The short and explicit answer is that you need to specify the attribute axis (or short form @) to access attributes, like:

/nr:RTPPMDataMsgV1/nr:RTPPMData/nr:NationalPage/@WebDisplayPeriod
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜