Blog Tip - blog 技巧

Saturday, June 17, 2006

Zvon XSLT Tutorial

  1. 某处xml片段该采用哪个template取决其所在位置(XPATH), 其xpath匹配哪个template就采用哪个template
  2. xslt对匹配原始内容的处理有有两种方式:xsl:value-of 和xls:apply-templates ,两者的区别是前者不再对匹配的内容进行处理,后都则对匹配的内容再进行xslt处理

  3. xslt处理总是从匹配根节点(xpath="/")的模板开始的,此模板不一定需要强制指定,没有定义此模板则采用默认方式处理:处理所有节点包括text nodes,采用xsl:apply-templates方式;如果指定了根节点的处理模块,默认处理规则就不会再应用,如果此还你还想用其默认规则,则必须在xsl模板中强制指明( xsl:apply-templates)

  4. 使用 mode一个元素可以被多次被匹配的相应模板进行处理.如果 xsl:apply-templates指定的mode不存在,则相当于不存指定的模块不执行此处理example

  5. 当多个模板匹配一个元素时需要有模板priority属性来决定执行哪个模板( 权值大的执行).如果模板未指定priority,它的值是根据一些规则计算出来的.CCC的权值小于CCC/CCC和AAA/CCC/CCC,但后两都权值相同,此时XSLT处理可能会报错,如果不报错,则执行出现在xsl文件最后的那个模板. xpath="*"小于任何指定的xpath. 计算的权值范围在(-0.5到0.5). exmaple

  6. 元素的属性值可通过在属性名前加"@"来获取
  7. 属性的处理方式和元素相同,定义模板时可匹配一指定属性

  8. Axes child axis:子节点(不包括子节点的子节点)
    descendant axis:: 子孙节点(当前节点内的所有节点)
    parent axis:: 父节点(不包括父节点的父节点)
    ancestor axis:: 祖先节点(父节点及其以上面的所有父节点的父节点)
    following-sibling:: 当前节点后面的所有同级节点
    preceding-sibling:: 当前节点前面的所有同级节点
    following:: 当前节点后面的所有节点,注意还包括祖先节点的following节点
    preceding:: 当前节点前面的所有节点,包括preceding-sibling节点及其下面的所有节点,但不包括祖先节点
    attribute:: 当前节点的所有属性节点
    namespace axis ?
    self:: 当前节点
    descendant-or-self::当前节点的子-孙节点及当前节点
    ancestor-or-self::当前节点的祖先节点及当前节点


  9. Axis child:: 可以省略,这是默认的axis.
    Axis attribute::可缩写成@
    /descendant-or-self::可略写成@ // 包括根节点及其下面的所有的所有节点
    self:: 可以缩写 .
    parent:: 可经缩写成 ..

  10. xsl:for-each 功能类似于一个模板,通过select属性选中的的第一个节点应用此模板

  11. xsl:call-template 可按名称调用模板,与不当前是否匹配不无关


  12. xsl:for-each与xsl:apply-templatess可能进行排序通过内勤嵌xsl:sort元素来根据(select)什么元素进行哪种顺序的排序(order:ascending descending ),还是指定排序的数据类型data-type(text,number),还可以指定大小写的顺序(case-order ; upper-first,lower-first)

  13. xsl:element 可根据其name属性动态生成元素


  14. xsl:attribute可根据其name属性动态生成元素属性

  15. xsl:copy-ofxsl:copy进行元素拷贝,两者的区别是copy只拷贝当前节点内的文本内容text(包括子节点内的text),不包括子节点及属性,copy-of则进行完全拷贝

  16. xsl:copy使用use-attribute-sets时拷贝当前元素(不包括属性和子节点)加入指定的属性集,

Read more at www.zvon.org/xxl/XSLTut...





Wednesday, April 13, 2005

blog atom可的时间格式

有用W3C Date-Time : YYYY-MM-DDThh:mm:ss.sTZD

Formats



Different standards may need different levels of granularity in the date
and
time, so this profile defines six levels.
Standards that reference this profile should specify one or more of these
granularities.
If a given standard allows more than one granularity, it should specify
the meaning of the dates and times with reduced precision,
for example, the result of comparing two dates with different precisions.



The formats are as follows.
Exactly the components shown here must be present, with exactly this
punctuation.
Note that the "T" appears literally in
the string, to indicate the beginning of the time element, as specified in
ISO 8601.



   Year:
YYYY (eg 1997)
Year and month:
YYYY-MM (eg 1997-07)
Complete date:
YYYY-MM-DD (eg 1997-07-16)
Complete date plus hours and minutes:
YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
Complete date plus hours, minutes and seconds:
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
Complete date plus hours, minutes, seconds and a decimal fraction of a
second
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)


where:



     YYYY = four-digit year
MM = two-digit month (01=January, etc.)
DD = two-digit day of month (01 through 31)
hh = two digits of hour (00 through 23) (am/pm NOT allowed)
mm = two digits of minute (00 through 59)
ss = two digits of second (00 through 59)
s = one or more digits representing a decimal fraction of a second
TZD = time zone designator (Z or +hh:mm or -hh:mm)


This profile does not specify how many digits may be used to represent
the decimal fraction of a second. An adopting standard that permits
fractions of a second must specify
both the minimum number of digits (a number greater than or equal to
one) and the maximum number of digits (the maximum may be stated to be
"unlimited").



This profile defines two ways of handling time zone offsets:




  1. Times are expressed in UTC (Coordinated Universal Time), with a
    special UTC designator ("Z").
  2. Times are expressed in local time, together with a time zone offset
    in hours and minutes. A time zone offset of "+hh:mm" indicates that
    the date/time uses a local time zone which is "hh" hours and "mm"
    minutes ahead of UTC. A time zone offset of "-hh:mm" indicates that
    the date/time uses a local time zone which is "hh" hours and "mm"
    minutes behind UTC.


A standard referencing this profile should permit one or both of these
ways of handling time zone offsets.



ref