xsl-list
[Top] [All Lists]

Re: [xsl] [XSL] id() in Ancestor Nodes?

2007-10-04 04:05:08
Hi,

 I should make the declarations here a little clear.

For those of you who are wondering if I had declared all these things. I use a RelaxNG to declare all my attributes, which the file is really long, but the file itself is valid. I try to use id function in XSLT to extract the
publication id information from the "attribute" and have the output
display the name of the publisher itself as it is in HTML. The complete code is
as follows:


XML:

<bookshelf>
  <bookshelfHeader>
      <fileDesc>
          <titleStmt>
              <title>My Book Collection</title>
              <principal>2007</principal>
          </titleStmt>
          <publicationStmt>
              <topic>Technology</topic>
              <date value="2007-10-03">2007</date>
          </publicationStmt>
          <sourceDesc>
              <biblFull>
                  <titleStmt>
                      <title level="monograph" type="main">Technical
Book Collection</title>
                     </titleStmt>
              </biblFull>
          </sourceDesc>
      </fileDesc>
      <profileDesc>
          <publisherList>
              <publisherItem>
                  <publication xml:id="apress">Apress</publication>
              </publisherItem>
              <publisherItem>
                  <publication xml:id="oreilly">O'Reilly</publication>
              </publisherItem>
              <publisherItem>
                  <publication xml:id="wrox">Wrox</publication>
              </publisherItem>

          </publisherList>
      </profileDesc>
  </bookshelfHeader>
  <text>
      <body>
          <bookGroup>
              <collection type="xslt">
                  <book publish="wrox" date="2002">
                      <title>
                          <emph>Beginning XSLT</emph>
                      </title>
                     <title>
                         <emph>Essential XML Quick
                         Reference</emph></title>
                  </book>
                  <book publish="oreilly" date="2003">
                      <title>
                          <emph>.NET and XML</emph>
                      </title>
                  </book>
              </collection>
          </bookGroup>
      </body>
  </text>
</bookshelf>

XSLT that is Working but Hard to Manage:

  <xsl:template match="book">
  <div>
                  <xsl:call-template name="bookpublisher" />
          <span><xsl:apply-templates/>
          </span>
  </div>
</xsl:template>

<xsl:template name="bookpublisher">
  <span class="bookpublisher">
      Books Published by
      <xsl:choose>
          <xsl:when test="./@publish ='wrox'">Wrox</xsl:when>
          <xsl:when test="./@publish ='oreilly'">Oreilly</xsl:when>
      </xsl:choose>,
      <xsl:attribute name="class">
          <xsl:value-of select="./@date" />
      </xsl:attribute>.
  </span>
</xsl:template>

<xsl:template match="title">
  <i><xsl:apply-templates/></i>
</xsl:template>

<xsl:template match="emph">
  <b><xsl:apply-templates/></b>
</xsl:template>

There is no problem with the functionality of the code above, but when
there are more id's to insert, I have to keep on adding the names to
the "<xsl:when test=""> list. I tried using the id function:

<xsl:template name="bookpublisher">
      <xsl:variable name="name" select="id('@publish')"/>
          <span class="character">
          <xsl:value-of select="$name"/>
      </span>
  </xsl:template>

The output does not give me anything other than the other information
in the <xsl:apply-templates> section. I should add to the answer of your doubts that when I use something <xsl:value-of select="./@date"> and <xsl:value-of select="./@publish"/> prints information properly of the original "attribute", but what it does not do is that it does not print out things outside the attributes as shown in the publisherItem section.

Can anyone please tell me what I have done wrong?

Thanks to those who can help.

Alice


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>