2017-02-09 4 views
0

CSS로 이미지 배치를 제어 할 수 있도록 숫자 래퍼에 클래스 값을 추가 할 수 있도록 이미지 너비를 숫자로 저장하려고합니다. 작은, 중간 또는 큰 이미지).xsl을 사용하여 변수에 숫자로 이미지 너비를 저장하는 방법

이것은 내 XML 예이다 :

<?xml version="1.0" encoding="UTF-8"?> 
<root> 
    <section> 
     <figure class="informalfigure"> 
      <img src="../images/image-fpo-1.png" alt="" width="250" height="800"/> 
     </figure> 
     <figure class="informalfigure"> 
      <img src="../images/image-fpo-2.png" alt="" width="650" height="800"/> 
     </figure> 
     <figure class="informalfigure"> 
      <img src="../images/image-fpo-3.png" alt="" width="1250" height="800"/> 
     </figure> 
    </section> 
</root> 

이것은 내 XSLT이다 변수 "IMG 폭"은 끊기를 일으키는

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> 

<xsl:variable name="small-image"> 
    <xsl:number value="200"/> 
</xsl:variable> 
<xsl:variable name="medium-image"> 
    <xsl:number value="500"/> 
</xsl:variable> 
<xsl:variable name="large-image"> 
    <xsl:number value="1000"/> 
</xsl:variable> 

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

<xsl:template match="figure"> 
    <xsl:variable name="classvalue" select="@class"/> 
    <xsl:variable name="img-width" select="number(img[@width])"/> 

    <xsl:choose> 
     <xsl:when test="number($img-width) > number($large-image)"> 
      <figure class="{$classvalue} large"> 
       <xsl:apply-templates/> 
      </figure> 
     </xsl:when> 
     <xsl:when test="number($img-width) > number($medium-image)"> 
      <figure class="{$classvalue} medium"> 
       <xsl:apply-templates/> 
      </figure> 
     </xsl:when> 
     <xsl:when test="number($img-width) > number($small-image)"> 
      <figure class="{$classvalue} small"> 
       <xsl:apply-templates/> 
      </figure> 
     </xsl:when> 
     <xsl:otherwise> 
      <figure class="{$classvalue} missedit" width="{$img-width}"> 
       <xsl:apply-templates/> 
      </figure> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 
</xsl:stylesheet> 

. 나는 분명히 거기에 뭔가 잘못된 것이있다. 어떻게하면 이미지 너비를 숫자 변수로 저장하여 테스트 할 수 있습니까? 어떤 도움이라도 대단히 감사합니다. 감사합니다, 존

답변

0

당신은 당신이하지 "이미지 데이터는"변수 "이미지 너비"에

를 저장하기 때문에

<xsl:variable name="img-width" select="number(img/@width)"/> 

<xsl:variable name="img-width" select="number(img[@width])"/> 

을 변경해야