2012-03-19 4 views
1

xslt를 사용하고 있습니다. 내가 항목 태그의 확인해야 xslt에서 태그의 값을 확인하는 방법

<entry colsep="0" rowsep="0" /> 
<entry colsep="0" rowsep="0">Acid suppressant</entry> 

처럼 내 입력 문자열 인 경우 값이 포함되어 있습니다. 그렇지 않은 경우이를 바꿔야합니다.

<entry colsep="0" rowsep="0">...</entry> 

XSLT에서이를 확인하는 방법. 당신은 어떤 텍스트 값을 가진 요소를 일치 시키려면

감사 푸자

답변

2

, 당신은 단순히 당신은 다음 코드를 추가 할 수 있습니다

<xsl:template match="entry[not(text())]" > 

이 요소를 복사 할 수 있지만, 기본을 추가 할 수 있습니다 동시에 가치.

, 변환 정체성이 결합은 다음의 XML에 적용된 다음 XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="entry[not(text())]"> 
     <entry> 
     <xsl:copy-of select="@*"/> 
     <xsl:text>Default Value</xsl:text> 
     </entry> 
    </xsl:template> 

    <xsl:template match="@*|node()"> 
     <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

제공 다음

<entries> 
    <entry colsep="0" rowsep="0" /> 
    <entry colsep="0" rowsep="0">Acid suppressant</entry> 
</entries> 

인에게 출력

<entries> 
    <entry colsep="0" rowsep="0">Default Value</entry> 
    <entry colsep="0" rowsep="0">Acid suppressant</entry> 
</entries> 
관련 문제