Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
787 views
in Technique[技术] by (71.8m points)

xslt - Conditionally displaying data from XML using XSLT1?

Here is a XML snippet:

<div class="headingZoom">
  <xsl:text>Congregation Meeting Schedule for </xsl:text>  
  <xsl:value-of select="MeetingWorkBook/Meeting[1]/MeetingDate/@MonthFull"/>
  <xsl:text> </xsl:text>
  <xsl:value-of select="MeetingWorkBook/Meeting[1]/MeetingDate/@Year"/>

  <xsl:text> - </xsl:text>

  <xsl:value-of select="MeetingWorkBook/Meeting[last()]/MeetingDate/@MonthFull"/>
  <xsl:text> </xsl:text>
  <xsl:value-of select="MeetingWorkBook/Meeting[last()]/MeetingDate/@Year"/>

  <xsl:value-of select="MeetingWorkBook/Meeting[last()]/SpecialEvent/Date/@MonthFull"/>
  <xsl:text> </xsl:text>
  <xsl:value-of select="MeetingWorkBook/Meeting[last()]/SpecialEvent/Date/@Year"/>
</div>

The problem is that the last element will be one or the other:

  • This one:
<xsl:value-of select="MeetingWorkBook/Meeting[last()]/MeetingDate/@MonthFull"/>
<xsl:text> </xsl:text>
<xsl:value-of select="MeetingWorkBook/Meeting[last()]/MeetingDate/@Year"/>
  • Or this one:
<xsl:value-of select="MeetingWorkBook/Meeting[last()]/SpecialEvent/Date/@MonthFull"/>
<xsl:text> </xsl:text>
<xsl:value-of select="MeetingWorkBook/Meeting[last()]/SpecialEvent/Date/@Year"/>

How can I do that with XSLT-1?


Infact, upon reflection, even this bit needs to apply the same logic where I display the data for Meeting[1]. It too could be one or the other type of element.

I should point out that it would never have both in teh relevant nodes, just one or the other.


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

1 Answer

0 votes
by (71.8m points)
<xsl:value-of select="MeetingWorkBook/Meeting[last()]//@MonthFull"/>
<xsl:text> </xsl:text>
<xsl:value-of select="MeetingWorkBook/Meeting[last()]//@Year"/>

Please note the double slash.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...