2014-01-16 6 views
1

У меня есть числовой параметр numberOfFileds с целым числом. мне нужно создать numberOfFileds +1 XML узлы со следующей структурой:Динамическое создание имени тега XML в xslt

<CONT_CUST_FLD_00X> 
    <xsl:value-of 
      select="./platformCore:customField[@internalId='custrecord_ebiz_container_custfield_00X']/platformCore:value"/> 
</CONT_CUST_FLD_00X> 

где X - числа от 0 до numberOfFileds

Так, например, когда numberOfFileds = 3 прогнозируемый выход должен быть следующим:

<CONT_CUST_FLD_000> 
    <xsl:value-of 
      select="./platformCore:customField[@internalId='custrecord_ebiz_container_custfield_000']/platformCore:value"/> 
</CONT_CUST_FLD_000> 
<CONT_CUST_FLD_001> 
    <xsl:value-of 
      select="./platformCore:customField[@internalId='custrecord_ebiz_container_custfield_001']/platformCore:value"/> 
</CONT_CUST_FLD_001> 
<CONT_CUST_FLD_002> 
    <xsl:value-of 
      select="./platformCore:customField[@internalId='custrecord_ebiz_container_custfield_002']/platformCore:value"/> 
</CONT_CUST_FLD_002> 
<CONT_CUST_FLD_003> 
    <xsl:value-of 
      select="./platformCore:customField[@internalId='custrecord_ebiz_container_custfield_003']/platformCore:value"/> 
</CONT_CUST_FLD_003> 

Пожалуйста, помогите мне реализовать это, написав соответствующий шаблон xslt.

ответ

0

Я выбрала немного другой путь решения вопроса:

Вот мой шаблон:

<xsl:template name="createFieldsAuto"> 
    <xsl:param name="newTagName"/> 
    <xsl:param name="internaIdValue"/> 
    <xsl:param name="numberOfFields"/> 
    <xsl:param name="cycleIndex" select="0"/> 
    <xsl:if test="number($cycleIndex) &lt;= number($numberOfFields)"> 
     <xsl:variable name="a" select="concat($internaIdValue, $cycleIndex)"/> 
     <xsl:element name="{concat($newTagName, $cycleIndex)}"> 
      <xsl:value-of 
        select="./platformCore:customField[@internalId=concat($internaIdValue, $cycleIndex)]/platformCore:value"/> 
     </xsl:element> 
     <xsl:call-template name="createFieldsAuto"> 
      <xsl:with-param name="newTagName" select="$newTagName"/> 
      <xsl:with-param name="internaIdValue" select="$internaIdValue"/> 
      <xsl:with-param name="numberOfFields" select="$numberOfFields"/> 
      <xsl:with-param name="cycleIndex" select="$cycleIndex + 1"/> 
     </xsl:call-template> 
    </xsl:if> 
</xsl:template> 

А вот как я это называю:

<!--the template below helps us to generate sections like these:--> 

<!--<BILL_INFO_CUST_FLD_000 ></BILL_INFO_CUST_FLD_000 >--> 
<!--<BILL_INFO_CUST_FLD_001 ></BILL_INFO_CUST_FLD_001 >--> 
<!--<BILL_INFO_CUST_FLD_002 ></BILL_INFO_CUST_FLD_002 >--> 

<!--example of using is the following:--> 

<xsl:variable name="custFields_SH_CUST"> 
    <xsl:call-template name="createFieldsAuto"> 
     <xsl:with-param name="newTagName" select="'CONT_CUST_FLD_00'"/> 
     <xsl:with-param name="internaIdValue" select="'custrecord_ebiz_container_custfield_00'"/> 
     <xsl:with-param name="numberOfFields" select="9"/> 
    </xsl:call-template> 
</xsl:variable> 
<xsl:copy-of select="$custFields_SH_CUST"/> 
2

Вы можете использовать шаблон значения атрибута для атрибута namexsl:element для создания элементов с вычисленными именами. Я бы подошел к такой проблеме:

<xsl:for-each select="platformCore:customField[ 
    starts-with(@internalId, 'custrecord_ebiz_container_custfield_')]"> 
    <xsl:element name="CONT_CUST_FLD_{substring-after(@internalId, 'custrecord_ebiz_container_custfield_')}"> 
    <xsl:value-of select="platformCore:value" /> 
    </xsl:element> 
</xsl:for-each> 

Это может быть шаблон, а не каждый для каждого.

Смежные вопросы