2017-04-11 10 views
0

私はxml初心者です。私はxmlファイルを使用してアクティブなディレクトリから属性を取得してユーザフィールドに入力するファックスサーバに取り組んでいます。私は1つの価値を除いて、私が望むようにすべての仕事をしています。この値は、ファックスサーバーのユーザープロファイルに表示される1つの文字列に2つの属性を組み合わせる必要があります。私は "PersonalVoiceNum"フィールドに表示する "888.888.8888 x254"形式にAD属性のtelephoneNumberとipPhoneを組み合わせようとしています。メインラインの後に拡張子が付きます。 "x"はAD属性にはありませんが、可能ならばそれを追加したいと思います。私はそれらを結合するために、concatとstring-joinを使用しようとしましたが、どちらも成功していません。彼らは働かないと言っているわけではありません。私はちょうどそれを正しくフォーマットする経験がありません。コードブロックの2番目のビットは、私が結合しようとしている2つの属性です。 ?xml version = "1.0"で始まるセクション?ファイル内のコード全体です。どんな助けでも大歓迎です。XSLT Template Concat 2つの文字列

最後の目標は、XMLコードの "PersonalVoiceNum"属性を設定することです。 "telephoneNumber"と "ipPhone"は私が引き出しているアクティブなディレクトリ属性です。私の今コードの2番目のセクションは、 "PersonalVoiceNum"にtelephoneNumberまたはipPhone属性のいずれかを設定できることを示しています。私はipPhone属性が現在定義されているxslのいずれかにプラグインできることを示すために、それらを置いています。 "PersonalVoiceNum"に2つの組み合わせを設定したいと思います。したがって、telephoneNumberまたはipPhone番号だけを表示するのではなく、xmlで次のようになります。

ソリューション

 <xsl:template match="rf:attr[@name='ipPhone']"> 
    <attr name="PersonalVoiceNum"> 
    <value> 
    <xsl:text> 888.888.8888 x</xsl:text> 
    <xsl:apply-templates select="*"/> 
    </value> 
    </attr> 
    </xsl:template> 

<attr name="PersonalVoiceNum"> 
<value>888.888.8888 x235</value> 
</attr> 

 <xsl:template match="rf:attr[@name='telephoneNumber']"> 
<attr name="PersonalVoiceNum"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 
    <xsl:template match="rf:attr[@name='ipPhone']"> 
<attr name="PersonalVoiceNum"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 

全体XSLT

<?xml version="1.0"?> 
<xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:rf="urn:rightfax-sync-schema" 
xmlns="urn:rightfax-sync-schema" 
exclude-result-prefixes="rf" 
version="1.0"> 
<xsl:output method="xml" indent="yes"/> 

<!-- Copy all nodes and attributes. --> 
<xsl:template match="/ | @* | node()"> 
<xsl:copy> 
    <xsl:apply-templates select="@* | node()"/> 
</xsl:copy> 
</xsl:template> 

<!-- "userID" is a required attribute --> 
<xsl:template match="rf:attr[@name='sAMAccountName']"> 
<attr name="UserID"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='objectSid']"> 
<attr name="AssociatedNTAccountSID"> 
    <xsl:apply-templates select="*"/> 
</attr> 
<attr name="RequiresNTAuth"> 
    <value>True</value> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='company']"> 
<attr name="ToCompany"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='facsimileTelephoneNumber']"> 
<attr name="RouteCode"> 
    <value> 
    <!-- Get the last 4 digits of fax number, ignoring various special 
characters that might 
    be found in phone numbers. If result is Not a Number then use default 
route code instead. --> 
    <xsl:variable name="cleanNumber" select="translate(node(), ' .-,()', '')"/> 
    <xsl:variable name="routecode" select="substring($cleanNumber, string-length($cleanNumber)-3, 4)"/> 
    <xsl:choose> 
     <xsl:when test="string(number($routecode))='NaN'">100</xsl:when> 
     <xsl:otherwise><xsl:value-of select="$routecode"/></xsl:otherwise> 
    </xsl:choose> 
    </value> 
</attr> 
<attr name="PersonalFaxNum"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='l']"> 
<attr name="ToCityState"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='name']"> 
<attr name="UserName"> 
    <xsl:apply-templates select="*"/> 
</attr> 
<attr name="FromName"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='otherFacsimileTelephoneNumber']"> 
<attr name="GeneralFaxNum"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='otherTelephone']"> 
<attr name="GeneralVoiceNum"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 
<xsl:template match="rf:attr[@name='ipPhone']"> 
<attr name="PersonalVoiceNum"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='legacyExchangeDN']"> 
<attr name="RouteInfo"> 
    <xsl:apply-templates select="*"/> 
</attr> 
<attr name="RouteType"> 
    <value>11</value> <!-- Exchange = 11 --> 
</attr> 
<attr name="NotifyInfo"> 
    <xsl:apply-templates select="*"/> 
</attr> 
<attr name="NotifyType"> 
    <value>17</value> <!-- Exchange = 17 --> 
</attr> 
<attr name="RouteFormat"> 
    <value>2</value> <!-- TIFF = 2 --> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='msExchVoiceMailboxID']"> 
<attr name="BigVoiceMailSubscriberID"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='mail']"> 
<attr name="EmailAddress"> 
    <xsl:apply-templates select="*"/> 
</attr> 
<attr name="NotifyInfo"> 
    <xsl:apply-templates select="*"/> 
</attr> 
<attr name="NotifyType"> 
    <!-- Exchange = 17 --> 
    <value>17</value> 
</attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='ObjectSid']"> 
<attr name="SyncGuid"> 
    <xsl:apply-templates select="*"/> 
</attr> 
</xsl:template> 

</xsl:stylesheet> 

XML

<?xml version="1.0" encoding="utf-8"?> 
<syncRequest disabledUsers="Ignore" disabledExchangeUsers="ignore" 
xmlns="urn:rightfax-sync-schema"> 
<userAddRequest source="ActiveDirectory" 
guid="010194de60143a4e878fbc12af89eae2" moveToGroup=""> 
<attr name="ToCompany"> 
    <value>Company</value> 
</attr> 
<attr name="RouteCode"> 
    <value>6600</value> 
</attr> 
<attr name="PersonalFaxNum"> 
    <value>867.510.6500</value> 
</attr> 
<attr name="PersonalVoiceNum"> 
    <value>235</value> 
</attr> 
<attr name="ToCityState"> 
    <value>Chicago</value> 
</attr> 
<attr name="EmailAddress"> 
    <value>[email protected]</value> 
</attr> 
<attr name="NotifyInfo"> 
    <value>[email protected]</value> 
</attr> 
<attr name="NotifyType"> 
    <value>17</value> 
</attr> 
<attr name="UserName"> 
    <value>Chris Grif</value> 
</attr> 
<attr name="FromName"> 
    <value>Chris Grif</value> 
</attr> 
<attr name="AssociatedNTAccountSID"> 
    <value>S-1-5-21-2106057203-4278202381-757156151-2748</value> 
</attr> 
<attr name="RequiresNTAuth"> 
    <value>True</value> 
</attr> 
<attr name="UserID"> 
    <value>Chris.Grif</value> 
</attr> 
<attr name="telephoneNumber"> 
    <value>888.888.8888</value> 
</attr> 
</userAddRequest> 
+1

を? – Vinit

+0

Ditto @ Vinitのリクエスト:入力XMLがなければ、私たちは手伝ってはいけません。 –

+0

あなたが何を指しているのか分かりません。これは私が働いていたものすべてでした。 – Patrick

答えて

0
I'm trying to combine the AD attributes telephoneNumber and ipPhone into a "888.888.8888 x254" format to display in the "PersonalVoiceNum" field. 

あなたはこのような何か行うことができます:あなたにもXML構造を投稿することができます

<xsl:template match="rf:attr[@name='telephoneNumber']"> 
    <attr name="PersonalVoiceNum"> 
    <value> 
     <xsl:value-of select="."/> 
     <xsl:text> x</xsl:text> 
     <xsl:value-of select="../rf:attr[@name='ipPhone']"/> 
    </value> 
    </attr> 
</xsl:template> 

<xsl:template match="rf:attr[@name='ipPhone']"/> 
+0

それは何も生み出さなかった。コードが(目には)有効でない場合は、ユーザーをADからサーバーに同期させるだけではありません。 – Patrick

+2

「あなたはADからサーバーにユーザーを同期させる」という意味を理解できません。あなたのスタイルシートに収まるように自分のコードを適応させる必要があります。もしあなたがそれを働かせることができなければ、あなたの入力とスタイルシートの詳細を与えない限り、私たちはあなたを助けません。他の人がコメントしたように、あなたは私たちに不完全な情報を与えてしまったので、私の答えは必然的に不完全です。 –

+0

私の謝罪。コピー貼りの仕事だとは思わないはずです。私はそれを適応させ、それを働かせることができたので、それに感謝します。それはかなり単純であることが分かった。上記のコードを投稿します。 – Patrick