0

変換が必要な xsd ファイルでいっぱいのディレクトリがあり、それぞれの出力ファイルを生成する状況があります。スタイルシートを単一のドキュメントでうまく動作させていますが、それを拡張したいと思います。さて、今のところ xslt エディターは使用していません。saxon がインストールされています。ここにxsltファイルがあります:

<xsl:stylesheet version="1.0" 
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            >

<xsl:output method="text"/>

<!--* Ignore anything that looks complicated *-->
<xsl:template match="xsd:attribute 
                   | xsd:attributeGroup
                   | xsd:group
                   | xsd:schema/xsd:element[@type]
                   | xsd:notation
                   | xsd:annotation
                   "/>
<!--* Ignore text nodes (otherwise the output will be
  * inundated with whitespace) *-->

<xsl:template match="text()"/>

 <!--* Top-level elements with local complex types; those
  * we want to handle.
  *-->

<xsl:template match = "xsd:schema/xsd:element[xsd:complexType]">
<xsl:apply-templates/>
  </xsl:template>

  <!--* Aha!  A complex type whose content model we want to turn 
  * into a regular expression 
  *-->

<xsl:template match = "xsd:element/xsd:complexType
                     [xsd:sequence | xsd:choice | xsd:all]">
<!--* write out the name for the named regex *-->
<xsl:value-of select="concat('&#xA;&#xA;',
                      @name, parent::xsd:element/@name, 
                      ' ')"/>
<!--* write out the regex *-->
<xsl:apply-templates/>
</xsl:template>

<!--* Simple recursive case:  we encounter a model group. *-->

<xsl:template match = "xsd:sequence|xsd:choice|xsd:all">
<!--* Parenthesize the group and handle its children. *-->
<xsl:text>(</xsl:text>
<xsl:apply-templates/>
<xsl:text>)</xsl:text>

<!--* Append *, ?, +, or {min, max}. *-->
<xsl:call-template name="occurrence-indicator"/>

<!--* If our parent has further children, 
    * append the appropriate connector. *-->
<xsl:call-template name="connector"/>
</xsl:template>

<!--* An element in a content model. *-->
  <xsl:template match = "xsd:element[ancestor::xsd:complexType]">
<!--* Write out the element's name.  We're lazy so 
    * we don't bother with a QName for a local element.
    * Also, we don't recur. *-->
<xsl:value-of select="concat(@ref, @name)"/>

<!--* Handle occurrence indicator and connect
    * just as for groups. *-->
<xsl:call-template name="occurrence-indicator"/>
<xsl:call-template name="connector"/>
</xsl:template>


<!--* Emit the appropriate occurrence indicator for
  * a group or element.
  * Use {min,max}, {min,}, or {n} notation for 
  * non-standard occurrence counts.
  *-->

<xsl:template name="occurrence-indicator">
<xsl:choose>
  <xsl:when test="(@minOccurs='1' or not(@minOccurs)) 
                  and 
                  (@maxOccurs='1' or not(@maxOccurs))">
    <xsl:text></xsl:text>
  </xsl:when>
  <xsl:when test="@minOccurs='0' 
                  and 
                  (@maxOccurs='1' or not(@maxOccurs))">
    <xsl:text>?</xsl:text>
  </xsl:when>
  <xsl:when test="@minOccurs='0' and @maxOccurs='unbounded'">
    <xsl:text>*</xsl:text>
  </xsl:when>
  <xsl:when test="(@minOccurs='1' or not(@minOccurs)) 
                  and 
                  @maxOccurs='unbounded'">
    <xsl:text>+</xsl:text>
  </xsl:when>
  <xsl:when test="@minOccurs=@maxOccurs">
    <xsl:value-of select="concat('{', @minOccurs,'}')"/>
  </xsl:when>
  <xsl:when test="@maxOccurs='unbounded'">
    <xsl:value-of select="concat('{', @minOccurs,',}')"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="concat('{', 
                          @minOccurs,
                          ',',
                          @maxOccurs,
                          '}')"/>
  </xsl:otherwise>
</xsl:choose>
  </xsl:template>

  <xsl:template name="connector">
<!--* Emit the appropriate connector, if we need one. *-->
<xsl:if test="following-sibling::*[self::xsd:sequence 
              | self::xsd:choice 
              | self::xsd:all 
              | self::xsd:element]">
  <xsl:choose>
    <xsl:when test="parent::xsd:sequence">
      <xsl:text>, </xsl:text>
    </xsl:when>
    <xsl:when test="parent::xsd:choice">
      <xsl:text> | </xsl:text>
    </xsl:when>
    <xsl:when test="parent::xsd:all">
      <xsl:text> &amp; </xsl:text>
    </xsl:when>
  </xsl:choose>
</xsl:if>
  </xsl:template>

</xsl:stylesheet>
4

2 に答える 2

0

bash シェルにアクセスできる場合は、次の方法で実行できます。処理するファイルを含むディレクトリに移動して入力します。

for schemadoc in *.xsd
  do echo "$schemadoc ..."
  xsltproc myxslt.xsl $schemadoc > $schemadoc.output.txt
done

その際、実行しようとしているスタイルシートの名前に変更し、コマンド ラインから XSLT プロセッサを呼び出す正しい方法に合わせてmyxslt.xsl行頭を変更します。xsltproc

または、Oxygen にアクセスできる場合は、特定のディレクトリ内のすべてのファイル (またはすべての *.xsd ファイル) にスタイルシートを適用する方法を読んで、その方法で実行できます。

または、これらのいずれにもアクセスできない場合は、自分がいるコンピューティング環境で成功し、幸せに働いている人を見つけて、どのようにそれを行うかを尋ねてください.

ファイルのコレクションに対してプロセスを実行することは基本的なスキルであり、実行する方法は非常にたくさんあります。XSLT スタイルシートの特定の内容とはまったく関係がなく、何らかの理由で単一の XSLT プロセス内で実行する必要がある場合を除き、基本的には XSLT の質問ではありません (その場合、Dimitre Novatchev の言うことに注意深く耳を傾けてください)。 . 自分の環境で機能する 1 つ、3 つ、または 55 の方法を見つけて、それらを学びます。

于 2012-08-21T17:11:16.673 に答える