다음을 통해 공유


contains 함수

첫 번째 인수 문자열에 두 번째 인수 문자열이 포함되었는지 확인합니다.

boolean contains(str1, str2)

매개 변수

  • str1
    두 번째 인수를 포함할 수 있는 문자열입니다.

  • str2
    첫 번째 인수에 포함될 수 있는 문자열입니다.

반환 값

첫 번째 인수 문자열에 두 번째 인수 문자열이 포함되면 true를 반환하고그렇지 않으면 false를 반환합니다.

주의

인수가 문자열 형식이 아닌 경우 먼저 string() 함수를 사용하여 문자열로 변환된 다음 이 변환 결과가 평가됩니다.

경고

이 함수에 인수로 전달되는 노드 집합의 문자열변환으로 인해 예기치 않은 결과가 나타날 수 있습니다.자세한 내용은 string 함수을 참조하십시오.

이 함수는 대/소문자를 구분합니다.

다음 예제에서는 contains() 함수를 사용하여 제목에 "Pattern"이라는 단어가 포함된 book 컬렉션을 쿼리하는 방법을 설명합니다.

XML 파일(contains.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" 

href="contains.xsl"?>      
<bookstore>
  <book>
     <title>The Weather Pattern</title>
     <author>Weather Man</author>
     <price>100.00</price>
  </book>
  <book>
     <title>Weaving Patterns</title>
     <author>Weaver</author>
     <price>150.00</price>
  </book>
  <book>
     <title>Speech Pattern</title>
     <author>Speaker</author>
     <price>15.00</price>
  </book>
  <book>
     <title>Writing Style</title>
     <author>Writer</author>
     <price>1500.00</price>
  </book>
</bookstore>

XSLT 파일(contains.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"           

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html"   
     omit-xml-declaration="yes"/>

  <xsl:template match="/">
    <html>
       <head><title>example</title></head>
    <body>
       <xsl:apply-templates select="//book"/>
    </body>
    </html>
  </xsl:template>

  <xsl:template match="book">
     <xsl:if test="contains(title, 'Pattern')">
       <DIV>
         <B><xsl:value-of select="title"/></B> by 
         <I><xsl:value-of select="author"/></I> costs
         <xsl:value-of select="price"/>.
       </DIV>
     </xsl:if>
  </xsl:template>

</xsl:stylesheet>

출력

XML 파일(contains.xml)에 적용하면 위의 XSLT 스타일시트는 다음 출력을 생성합니다.

Weather Man에 의한 The Weather Pattern 비용은 100.00입니다.

Weaver에 의한 Weaving Patterns 비용은 150.00입니다.

Speaker에 의한 Speech Pattern 비용은 15.00입니다.

참고 항목

참조

string 함수

XML 데이터 형식 참조