0

xmltransformを使用して外部xlstファイルを使用してxmlを変換するAppleScriptがあります。xsltファイルによって取得される変数をapplescriptに追加したいと思います。satimageディクショナリは、xmltransformの一部としてのxsl paramsの使用について説明していますが、例が見つかりません。

テンプレートを使用してXMLTransform xmlFile with xsltFile in outputpath 、applescriptと次のxslファイルの例の両方で変数をどのように定義しますか。

<xsl:stylesheet version="1.0">
    <xsl:param name="vb1" value="'unknown'"/>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="xmeml/list/name">
    <xsl:value-of select="{$vb1}"/>
  </xsl:template>
</xsl:stylesheet>

Applescriptスニペット

set vb1 to "Hello" as string
XMLTransform xmlFile with xsltFile1 in outputpathtemp xsl params vb1

現在のapplescriptは、「vb1をレコードにできません」を返します。

私は今、以下を使用することを検討していますが、XMLでNULLを返しています

set vb1 to {s:"'hello'"}
XMLTransform xmlFile with xsltFile1 in outputpathtemp xsl string params vb1

入力は

<xmeml>
   <list> 
     <name>IMaName</name>
     <!-- other nodes -->
   </list>
</xmeml>

現在の出力は

<xmeml>
   <list> 
     <name/>
     <!-- other nodes -->
   </list>
</xmeml>

誰か助けてもらえますか?どうもありがとう。

4

3 に答える 3

1

xsl paramsレコードまたはリストが必要

生の文字列パラメータは引用符で囲む必要があります

set vb1 to "'Hello'" -- added simple quote
XMLTransform xmlFile with xsltFile1 in outputpathtemp xsl params {vb1} --  {} = list
于 2012-07-25T01:07:02.873 に答える
1

パラメーターを使用してXSLTを呼び出す場合、パラメーターは内部的にXSLT内の変数(および関数に送信されるパラメーターと同様)に非常によく似ているため、パラメーターを名前として渡すと、次のようになります。

<xsl:stylesheet version="1.0">
  <xsl:parameter name="paramname" value="'unknown'"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="xmeml/list/name">
    <xsl:value-of select="{$paramname}"/>
  </xsl:template>
</xsl:stylesheet>

このインスタンスでパラメーターを渡すときは、「paramname」という名前を使用します(ただし、他の何かが良いかもしれません!)。何も渡さない場合に備えて、値があります。そうした場合、それは置き換えられます。

于 2012-07-24T09:33:02.803 に答える
0

答えは次のとおりです。

applescript

XMLTransform xmlFile with xsltFile1 in outputpathtemp xsl params {"vb1", "'hello'"}

XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:param name="vb1" />

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy> 
</xsl:template>

<xsl:template match="/xmeml/list/name">
<xsl:element name="name">
       <xsl:value-of select="$vb1"/>
    </xsl:element>
 </xsl:template>
</xsl:stylesheet>

ありがとう。

于 2012-07-25T10:41:59.847 に答える