2017-12-08 10 views
0

여러 개의 숫자가 큰 따옴표로 묶여있는 변수를 처리 할 수 ​​있습니까? 예. 따옴표를 마침표로 변환하면 xslt 1.0의 Translate 함수가 오류를 반환합니다. 하나 이상의 항목 시퀀스가 ​​translate() ("2", "1", "1")의 첫 번째 인수로 허용되지 않음큰 따옴표로 묶은 여러 숫자 변환 (XSLT 1.0)

나는) (.2.1.1로 번역했다.)

XML

<?xml version="1.0" encoding="ISO-8859-1"?> 
<Project type="cim" version="0.1"> 
    <Projects> 
    <WBSs> 
     <WBS GUID=”2”> 
     <WBSs> 
      <WBS GUID=”1”> 
      </WBS> 
       <WBSs> 
       <WBS GUID=”1”> 
       </WBS> 
       </WBSs> 
      <WBS GUID=”2”> 
      </WBS> 
      <WBS GUID=”3”> 
       <WBSs> 
       <WBS GUID=”4”> 
       </WBS> 
       </WBSs> 
      </WBS> 
     </WBSs> 
     <WBS GUID=”4”> 
      <WBSs> 
      <WBS GUID=”5”> 
      </WBS> 
      <WBS GUID=”8”> 
      </WBS> 
      <WBS GUID=”2”> 
      </WBS> 
      <WBS GUID=”10”> 
      </WBS> 
     </WBSs> 
     </WBS> 
    </WBSs> 
    </Projects> 
</Project> 

XSLT

<xsl:variable name="NETWORK "> 
    <xsl:apply-templates select=".//WBS" mode="I_NETWORK">     
    <xsl:with-param name="ProjectId" select="$ProjectId"/> 
    </xsl:apply-templates> 
</xsl:variable> 

<xsl:template match="WBS" mode="I_NETWORK"> 
    <xsl:param name="ProjectId"/> 

<xsl:variable name="wbsCode" select="@GUID"/> 
<xsl:variable name="quot">"</xsl:variable> 

<xsl:variable name="var1"> 
    <xsl:value-of select="translate($wbsCode,$quot,'.')"/> 

</xsl:template> 

답변

0
You have to use the real double quotes in your XML, "2", rather than the curvy double quotes, “2”. Once you have real double quotes in XML use the escape character to do your translate. Your editor may be putting the curvy double quotes in. 

<xsl:variable name="test"> 
    <xsl:value-of select="'(&quot;2&quot;,&quot;1&quot;,&quot;1&quot;)'"/> 
</xsl:variable> 

<xsl:variable name="result"> 
    <xsl:value-of select="translate($test,'&quot;','.')"/> 
</xsl:variable> 
+0

감사합니다, 나는 따옴표 두 세트가 있었다 몰랐어요. – Jkoul

+0

구문 검사 중에 프로세서가 따옴표를 삽입했을 수도 있습니다. 데이터를 볼 때 실제로 '2 1 1'(배도가없는)이므로 따옴표가 나타나지 않습니다. 'to' '.'로 번역하면 3 개의 항목이 첫 번째 인수로 전달되므로 번역 기능이 여전히 실패합니다. – Jkoul

+0

매력적인 이중 따옴표를 변형 할 수도 있습니다. 2 1 1에서 2.1.1로 변환하려는 경우 공백을로 변환 할 수 있습니다. 먼저 공간을 정규화 할 수 있습니다. 또는 문자열을 분리하고 원하는 빌드를 빌드 할 수 있습니다. 어쨌든, 행운을 빈다. – Bluewood66