0

タイトルと生年月日のリストをxmlファイルに出力しようとしています。しかし、コードにエラーが見つかりません。ここでは、xslでパラメーターがどのように機能するかを正確に理解するためにこれを試みています。

これがxmlコードです

<?xml-stylesheet type="text/xsl" href="aa.xslt"?> 
<tutorial>
    <section>
    <title>Gene Splicing for Young People</title>
    <panel>
        <title>Introduction1</title>
        <dob>86</dob>
        <dof>86</dof>
    <!-- ... -->
    </panel>
    <panel>
    <title>Discovering the secrets of life and creation</title>
    <dob>85</dob>
    <!-- ... -->
    </panel>
    <panel>
    <title>"I created him for good, but he's turned out evil!"</title>
    <dob>84</dob>
    <!-- ... -->
    </panel>
    <panel>
    <title>When angry mobs storm your castle</title>
    <dob>88</dob>
    <!-- ... -->
    </panel>
    </section>
</tutorial>

これがxsltコードです

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:template match="tutorial/section/panel">


  <xsl:call-tempate name="boo">
      <xsl:with-param name="myname" select="title" />
      <xsl:with-param name="mydob" select="dob" />
  </xsl:call-template>

</xsl:template>


 <xsl:template name="boo">
  <xsl:param name="myname" select="'Not Available'" />
  <xsl:param name="mydob" select="'Not Available'" />
  <div>
  NAME: <xsl:value-of select="$myname" />
  <br />
  DOB: <xsl:value-of select="$mydob" />
  <hr />
  </div>
</xsl:template> 
</xsl:stylesheet>

期待される出力は、Introduction1 86

発見....85

や。。など。

4

1 に答える 1

1

パネルのタイトルを出力しようとしているようですので、変更してみてください。

<xsl:template match="tutorial/section">

に:

<xsl:template match="tutorial/section/panel">

編集

「使用不可」の表示に問題がある場合は、要素が存在しないときにパラメータに空の文字列を渡しており、デフォルト値が上書きされていることが原因です。

あなたは次のようなことをすることができます:

<xsl:template match="tutorial/section/panel">
    <xsl:call-template name="boo">
        <xsl:with-param name="myname">
            <xsl:choose>
                <xsl:when test="title">
                    <xsl:value-of select="title"/>
                </xsl:when>
                <xsl:otherwise>Not Available</xsl:otherwise>
            </xsl:choose>
        </xsl:with-param>
        <xsl:with-param name="mydob">
            <xsl:choose>
                <xsl:when test="dob">
                    <xsl:value-of select="dob"/>
                </xsl:when>
                <xsl:otherwise>Not Available</xsl:otherwise>
            </xsl:choose>               
        </xsl:with-param>
    </xsl:call-template>
</xsl:template>

またはこのようなもの:

<xsl:template match="tutorial/section/panel">
    <xsl:choose>
        <xsl:when test="title and dob">
            <xsl:call-template name="boo">
                <xsl:with-param name="myname" select="title" />
                <xsl:with-param name="mydob" select="dob" />
            </xsl:call-template>
        </xsl:when>
        <xsl:when test="dob">
            <xsl:call-template name="boo">
                <xsl:with-param name="mydob" select="dob" />
            </xsl:call-template>                
        </xsl:when>
        <xsl:when test="title">
            <xsl:call-template name="boo">
                <xsl:with-param name="myname" select="title" />
            </xsl:call-template>                
        </xsl:when>
        <xsl:otherwise>
            <xsl:call-template name="boo"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
于 2013-02-11T05:12:58.913 に答える