2017-04-11 131 views
0

我將首先說我是一名XML新手。我正在使用一個xml文件的傳真服務器從活動目錄中提取屬性來填充用戶字段。除了一個值之外,我擁有一切按我想要的方式工作。對於這個值,我需要將兩個屬性合併爲一個顯示在傳真服務器的用戶配置文件中的字符串。我正在嘗試將AD屬性telephoneNumber和ipPhone合併爲一個「888.888.8888 x254」格式,以顯示在「PersonalVoiceNum」字段中。主線隨後延伸。 「x」不在AD屬性中,但如果可能,我想補充一點。我試圖使用concat和string-join來加入它們,但目前爲止還沒有成功。我並不是說他們不會工作。我只是沒有正確格式化的經驗。代碼塊中的第二位是我試圖組合的兩個屬性。以?xml version =「1.0」開頭的部分?是文件中的完整代碼。任何幫助將不勝感激。XSLT模板Concat兩個字符串

這裏的最終目標是填充xml代碼中的「PersonalVoiceNum」屬性。 「telephoneNumber」和「ipPhone」是我從中提取的主動目錄屬性。我現在的代碼第二部分顯示可以使用telephoneNumber或ipPhone屬性填充「PersonalVoiceNum」。我把它們放在那裏以表明你可以插入到當前定義了ipPhone屬性的xsl中。我希望它用兩者的組合來填充「PersonalVoiceNum」。所以它在xml中看起來如下所示,而不是僅顯示telephoneNumber或ipPhone號碼。

解決方案

 <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

你能後的XML結構呢? – 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. 

你可以做這樣的事情:

<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