Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
825 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...