2016-06-15 9 views
0

をusing input用textによってXMLをattributes:Replace valueはすべてこのexampleのXMLからXSLT maintaining XML identation

<?**xml** version='*1.0*' encoding='*UTF-8*' ?> 
<**config**> 
    <**Connections**> 
    <**DbMetaData** tablePrefix="*example.*"/> 
    <**AGSConnection** 
        outputDirectory="*C:\directory2\directories\isoutput*"     virtualOutputDirectory="*https://directory1.example1.net/ex/rest/output*"/> 
    <**SDEConnection** 
        server="*srv01*" 
        instance="*sde:sqlserver:srv01*" 
        database="*DBex*" 
        authenticationMode="*DBMS*" 
        user="*user1*" 
        password="*pass123*" 
        version="*sde.DEFAULT*" 
        sdeConnectionPath="*C:\\tmp\\ex\\conexion\\ser01.sde*"/> 
</**Connections**> 
</**config**> 

そしてXSLTをusing、indentation(XML用structureを)maintaining、全てがeditable textのfieldsによってvaluesをattribute replace。どのように私はこの?:

final result in browser

のようなものを得ることができたおかげで、

+1

** 1 ** **コード**に期待した結果を投稿してください。 - ** 2。**あなたの入力にあるすべてのアスタリスクの意味は何ですか? –

+1

ここでは、XML出力結果の「編集可能なテキストフィールド」とは何ですか? – nawazlj

+0

「インデントを保持する」とは、例えば余白をすべて意味します。 'outputDirectory'と' virtualOutputDirectory'ですか? xmlの観点からは、それらは無関係であり、xsltプロセッサーはそれらを取り除きますが、xml対応のアプリケーション以外のものを使用することは、良い解決策ではありません –

答えて

0

は、私はあなたが何を意味するかを推測してみましょう:あなただけの「いくつかの入力」と属性値を置き換えたいです。

xsltでは、document()関数を使用して読み取られた別のxmlドキュメントで "some input"を渡すことができます。また、パラメータを使用してスタイルシートに値を渡すこともできます。あなたがのparamsを渡す方法に-置き換えられる属性)

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:output method="xml" indent="yes"/> 

<xsl:param name="tablePrefix" select="''"/> 
<xsl:param name="outputDirectory" select="''"/> 
<xsl:param name="virtualOutputDirectory" select="''"/> 
<xsl:param name="server" select="''"/> 
<xsl:param name="instance" select="''"/> 
<xsl:param name="database" select="''"/> 
<xsl:param name="authenticationMode" select="''"/> 
<xsl:param name="user" select="''"/> 
<xsl:param name="password" select="''"/> 
<xsl:param name="version" select="''"/> 
<xsl:param name="sdeConnectionPath"/> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="@tablePrefix"> 
     <xsl:choose> 
      <xsl:when test="$tablePrefix != ''"> 
       <xsl:attribute name="tablePrefix"> 
        <xsl:value-of select="$tablePrefix"/> 
       </xsl:attribute> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:copy-of select="."/> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 
    <!-- repeat for each of the attributes replacing all "tablePrefix" by the attribute --> 

</xsl:stylesheet> 

は、あなたのXSLTプロセッサ、例えばに依存します--stringparam name value(xsltproc)または-param name value(xalanj)。

0

XMLパーサは、XSLTプロセッサに属性間の空白の量を通知しないため、データがXSLTに格納されると、この情報は失われます。 <xsl:output indent='yes'/>を使用してXSLTプロセッサに出力のインデントを行うことができますが、必ずしも元のものと同じである必要はありません。 (あなたが入力した文字のインデントは、奇妙なアスタリスクを無視すると、Saxonを使って作成されたかのように見えます)

関連する問題