我在通过 xslt 从 xml 文件生成 html 时遇到问题。 我将 tei 生成的 DTD 与漫画书的 cbml 自定义一起使用。
这是我的 xml 结构:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE TEI SYSTEM "cbml.dtd">
<?xml-stylesheet type="text/xsl" href="sorgente.xsl"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>Vi for Vendetta versione digitalizzata</title>
<respStmt>
<resp>codifica</resp>
<persName>Giulio Bambini</persName>
</respStmt>
<respStmt>
<resp>traduzione</resp>
<persName>Stefano Negrini</persName>
</respStmt>
<respStmt>
<resp>lettering</resp>
<persName>Maurizio Pieri</persName>
</respStmt>
</titleStmt>
<publicationStmt>
<publisher>Università di Pisa</publisher>
<pubPlace>Pisa, Italia</pubPlace>
<date>2015</date>
<availability>
<p>Licenza gratuita</p>
</availability>
</publicationStmt>
<sourceDesc>
<bibl>
<title>Vi for Vendetta</title>
<author>
<persName>Alan Oswald Moore</persName> e
<persName>David Lloyd</persName>
</author>
<publisher>DC Comics </publisher>
<pubPlace>Londra, Gran Bretagna</pubPlace>
<date>1982</date>
</bibl>
</sourceDesc>
</fileDesc>
<encodingDesc>
<projectDesc>
<p>
La seguente codifica con l'ausilio di Image Markup Tool ci permette di identificare il testo annotato sulle
immagini della Graphic Novel. All' interno del nostro elaborato i dialoghi sono stati evidenziati in corsivo e
sono stati inoltre raggruppati i nomi dei personaggi, delle organizzazioni e dei luoghi evidenziati nel testo.
</p>
</projectDesc>
</encodingDesc>
</teiHeader>
<facsimile>
<surface
xml:id="img-1"
ulx="0"
uly="0"
lrx="355"
lry="678">
<graphic url="tavole/1.jpg"/>
<zone
ulx="83"
uly="223"
lrx="272"
lry="256"
xml:id="line1"/>
<zone
ulx="92"
uly="251"
lrx="256"
lry="282"
xml:id="line2"/>
<zone
ulx="21"
uly="281"
lrx="330"
lry="308"
xml:id="line3"/>
<zone
ulx="36"
uly="306"
lrx="320"
lry="332"
xml:id="line4"/>
<zone
ulx="85"
uly="535"
lrx="249"
lry="556"
xml:id="line5"/>
<zone
ulx="97"
uly="556"
lrx="241"
lry="576"
xml:id="line6"/>
<zone
ulx="58"
uly="577"
lrx="281"
lry="595"
xml:id="line7"/>
<zone
ulx="68"
uly="595"
lrx="271"
lry="613"
xml:id="line8"/>
</surface>
</facsimile>
<facsimile>
<surface
xml:id="img-2"
ulx="0"
uly="0"
lrx="355"
lry="678">
<graphic url="tavole/2.jpg"/>
<zone
ulx="83"
uly="223"
lrx="272"
lry="256"
xml:id="line9"/>
<zone
ulx="92"
uly="251"
lrx="256"
lry="282"
xml:id="line10"/>
<zone
ulx="21"
uly="281"
lrx="330"
lry="308"
xml:id="line11"/>
<zone
ulx="36"
uly="306"
lrx="320"
lry="332"
xml:id="line12"/>
<zone
ulx="85"
uly="535"
lrx="249"
lry="556"
xml:id="line13"/>
<zone
ulx="97"
uly="556"
lrx="241"
lry="576"
xml:id="line14"/>
<zone
ulx="58"
uly="577"
lrx="281"
lry="595"
xml:id="line15"/>
<zone
ulx="68"
uly="595"
lrx="271"
lry="613"
xml:id="line16"/>
</surface>
</facsimile>
<text>
<body>
<div type="panelGrp" facs="img-1" xml:id="myElement-1">
<panel n="1" characters="#EmittenteRadioDelFato">
<balloon facs="line1" who="#EmittenteRadioDelFato" type="speech"><p>Buonasera Londra. Sono le nove, e questa è la<emph rendition="#b">voce del fato</emph> che trasmette sui 275 e 285
in onde medie... è il 5 novembre 1997.</p>
</balloon>
</panel>
<panel n="2" characters="#EmittenteRadioDelFato">
<balloon facs="#line2" type="speech" who="#EmittenteRadioDelFato"><p>Il tempo si manterrà bella fino alle 24:07, quando comincerà un <emph rendition="#b">acquazzone</emph> che durarà fino alle 01:30.</p>
</balloon>
</panel>
<panel n="3" characters="#EmittenteRadioDelFato">
<balloon facs="#line3" type="speech" who="#EmittenteRadioDelFato"><p>Per tutta la notte la temperatura resterà tra i 13 e i 14 gradi centigradi.</p>
</balloon>
</panel>
<panel n="4" characters="#EmittenteRadioDelFato">
<balloon facs="#line4" type="speech" who="#EmittenteRadioDelFato"><p>Si avverte la popolazione di Londra che da oggi le zone di Streatham e Brixton sono in <emph rendition="#b">quarantena</emph>.Si consiglia di evitare queste zone per motivi igienici e di sicurezza.</p>
</balloon>
</panel>
<panel n="5" characters="#EmittenteRadioDelFato">
<balloon facs="#line5" type="speech" who="#EmittenteRadioDelFato"><p>I dati di produttività dell'hereforshire lasciano sperare che nel febbraio del 1998 si possa porre fine al<emph rendition="#b">razionamento</emph> della carne.</p>
</balloon>
</panel>
<panel n="6" characters="#EmittenteRadioDelFato">
<balloon facs="#line6" type="speech" who="#EmittenteRadioDelFato"><p>Analoghe speranze anche per le <emph rendition="#b">uova</emph> e le <emph rendition="#b">patate</emph> grazie al'aumento della produzione.</p>
</balloon>
</panel>
<panel n="7" characters="#EmittenteRadioDelFato">
<balloon facs="#line7" type="speech" who="#EmittenteRadioDelFato"><p>Di primo mattino la polizia ha fatto irruzione in diciassette case della zona di Birmingham sgominando una pericolosa <emph rendition="#b">rete terroristica</emph>.</p>
</balloon>
<balloon facs="#line8" type="speech" who="#EmittenteRadioDelFato"><p>Venti persone, tra cui otto donne, sono attualmente detenute in attesa di giudizio.</p>
</balloon>
</panel>
<fw type="pageNum" place="lower-left">1</fw>
</div>
<div type="panelGrp" facs="img-2" xml:id="myElement-1">
<panel n="1" characters="#EmittenteRadioDelFato">
<balloon facs="line9" who="#EmittenteRadioDelFato" type="speech"><p>Buonasera Londra. Sono le nove, e questa è la<emph rendition="#b">voce del fato</emph> che trasmette sui 275 e 285
in onde medie... è il 5 novembre 1997.</p>
</balloon>
</panel>
<panel n="2" characters="#EmittenteRadioDelFato">
<balloon facs="#line10" type="speech" who="#EmittenteRadioDelFato"><p>Il tempo si manterrà bella fino alle 24:07, quando comincerà un <emph rendition="#b">acquazzone</emph> che durarà fino alle 01:30.</p>
</balloon>
</panel>
<panel n="3" characters="#EmittenteRadioDelFato">
<balloon facs="#line11" type="speech" who="#EmittenteRadioDelFato"><p>Per tutta la notte la temperatura resterà tra i 13 e i 14 gradi centigradi.</p>
</balloon>
</panel>
<panel n="4" characters="#EmittenteRadioDelFato">
<balloon facs="#line12" type="speech" who="#EmittenteRadioDelFato"><p>Si avverte la popolazione di Londra che da oggi le zone di Streatham e Brixton sono in <emph rendition="#b">quarantena</emph>.Si consiglia di evitare queste zone per motivi igienici e di sicurezza.</p>
</balloon>
</panel>
<panel n="5" characters="#EmittenteRadioDelFato">
<balloon facs="#line13" type="speech" who="#EmittenteRadioDelFato"><p>I dati di produttività dell'hereforshire lasciano sperare che nel febbraio del 1998 si possa porre fine al<emph rendition="#b">razionamento</emph> della carne.</p>
</balloon>
</panel>
<panel n="6" characters="#EmittenteRadioDelFato">
<balloon facs="#line14" type="speech" who="#EmittenteRadioDelFato"><p>Analoghe speranze anche per le <emph rendition="#b">uova</emph> e le <emph rendition="#b">patate</emph> grazie al'aumento della produzione.</p>
</balloon>
</panel>
<panel n="7" characters="#EmittenteRadioDelFato">
<balloon facs="#line15" type="speech" who="#EmittenteRadioDelFato"><p>Di primo mattino la polizia ha fatto irruzione in diciassette case della zona di Birmingham sgominando una pericolosa <emph rendition="#b">rete terroristica</emph>.</p>
</balloon>
<balloon facs="#line16" type="speech" who="#EmittenteRadioDelFato"><p>Venti persone, tra cui otto donne, sono attualmente detenute in attesa di giudizio.</p>
</balloon>
</panel>
<fw type="pageNum" place="lower-left">1</fw>
</div>
</body>
</text>
</TEI>
这是我生成 html 的 xsl 文件:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:cbml="http://www.cbml.org/ns/1.0">
<xsl:output method="html" version="4.0" indent="no"/>
<xsl:template match="/">
<xsl:text disable-output-escaping='yes'><!DOCTYPE html></xsl:text>
<html>
<head>
<title>
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:title"/>
</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="stile.css" />
</head>
<body>
<div>
<xsl:attribute name="class">inner-container</xsl:attribute>
<div>
<xsl:attribute name="id">corpo</xsl:attribute>
<xsl:apply-templates></xsl:apply-templates>
</div></div>
</body>
</html>
</xsl:template>
<xsl:template match="tei:teiHeader">
<div>
<xsl:attribute name="id">header</xsl:attribute>
<h1>
<xsl:attribute name="id">titolo</xsl:attribute>
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:title"/>
</h1>
<h3>
<xsl:attribute name="id">resp-name</xsl:attribute>
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:respStmt/tei:resp"/>
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:respStmt/tei:name"/>
</h3>
</div>
<xsl:element name="div">
<xsl:attribute name="id">contenitore-tei-header</xsl:attribute>
<xsl:element name="div">
<xsl:attribute name="id">informazioni-codifica</xsl:attribute>
<h3 class="titolo-liste">Informazioni sulla codifica</h3>
<h5>
Titolo:
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:title"/>
</h5>
<h5>
Codifica curata da:
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:respStmt/tei:persName"/>
</h5>
<h5>
Publisher:
<xsl:value-of select="tei:fileDesc/tei:publicationStmt/tei:publisher"/>
</h5>
<h5>
Città:
<xsl:value-of select="tei:fileDesc/tei:publicationStmt/tei:pubPlace"/>
</h5>
<h5>
Data:
<xsl:value-of select="tei:fileDesc/tei:publicationStmt/tei:date"/>
</h5>
</xsl:element>
<xsl:element name="div">
<xsl:attribute name="id">informazioni-fumetto</xsl:attribute>
<h3 class="titolo-liste">Informazioni sul fumetto</h3>
<h5>
Titolo originale:
<xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:bibl/tei:title"/>
</h5>
<h5>
Autori:
<a href="item.php?id={ItemId}">
<xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:bibl/tei:author/tei:persName"/>
</a>
</h5>
<h5>
Casa editrice:
<xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:bibl/tei:publisher"/>
</h5>
<h5>
Città:
<xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:bibl/tei:pubPlace"/>
</h5>
<h5>
Data pubblicazione:
<xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:bibl/tei:date"/>
</h5>
</xsl:element>
<xsl:element name="div">
<xsl:attribute name="id">introduzione</xsl:attribute>
<h3 class="titolo-liste">Introduzione</h3>
<xsl:value-of select="tei:encodingDesc/tei:projectDesc"/>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="tei:facsimile/tei:surface">
<xsl:element name="div">
<xsl:attribute name="id">contenitore-immagine</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="class">dimensioni</xsl:attribute>
<xsl:attribute name="src">
<xsl:value-of select="tei:graphic/@url" />
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="tei:text">
<xsl:apply-templates></xsl:apply-templates>
</xsl:template>
<xsl:template match="tei:body/tei:div[@type='panelGrp']">
<xsl:element name="div">
<xsl:attribute name="id">contenitore-testo-annotato</xsl:attribute>
<xsl:element name="ul">
<xsl:attribute name="class">ul-testo-annotato</xsl:attribute>
<xsl:for-each select="cbml:panel">
<xsl:element name="li">
<xsl:attribute name="class">li-testo-annotato</xsl:attribute>
<xsl:element name="p">
<xsl:attribute name="class">p-testo-annotato</xsl:attribute>
<xsl:value-of select="cbml:balloon"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
这是生成的 html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:cbml="http://www.cbml.org/ns/1.0"><head><title></title><meta http-equiv="content-type" content="text/html; charset=utf-8" /><link type="text/css" rel="stylesheet" href="stile.css" /></head><body><div class="inner-container"><div id="corpo">
<div id="header"><h1 id="titolo">Vi for Vendetta versione digitalizzata</h1><h3 id="resp-name">codifica</h3></div><div id="contenitore-tei-header"><div id="informazioni-codifica"><h3 class="titolo-liste">Informazioni sulla codifica</h3><h5>
Titolo:
Vi for Vendetta versione digitalizzata</h5><h5>
Codifica curata da:
Giulio Bambini</h5><h5>
Publisher:
Università di Pisa</h5><h5>
Città:
Pisa, Italia</h5><h5>
Data:
2015</h5></div><div id="informazioni-fumetto"><h3 class="titolo-liste">Informazioni sul fumetto</h3><h5>
Titolo originale:
Vi for Vendetta</h5><h5>
Autori:
<a href="item.php?id=">Alan Oswald Moore</a></h5><h5>
Casa editrice:
DC Comics </h5><h5>
Città:
Londra, Gran Bretagna</h5><h5>
Data pubblicazione:
1982</h5></div><div id="introduzione"><h3 class="titolo-liste">Introduzione</h3>
La seguente codifica con l'ausilio di Image Markup Tool ci permette di identificare il testo annotato sulle
immagini della Graphic Novel. All' interno del nostro elaborato i dialoghi sono stati evidenziati in corsivo e
sono stati inoltre raggruppati i nomi dei personaggi, delle organizzazioni e dei luoghi evidenziati nel testo.
</div></div>
<div id="contenitore-immagine"><img class="dimensioni" src="tavole/1.jpg" /></div>
<div id="contenitore-immagine"><img class="dimensioni" src="tavole/2.jpg" /></div>
<div id="contenitore-testo-annotato"><ul class="ul-testo-annotato"></ul></div>
<div id="contenitore-testo-annotato"><ul class="ul-testo-annotato"></ul></div>
</div></div></body></html>
我的问题是我想生成这个带有 altenated html 标签的 html 结构(类似的东西..):
<div id="contenitore-immagine">
<div id="contenitore-testo-annotato">
<div id="contenitore-immagine">
<div id="contenitore-testo-annotato">
但是对于我当前的 xsl,它带有这个错误的结构(它将所有元素匹配在一起而没有交替):
<div id="contenitore-immagine">
<div id="contenitore-immagine">
<div id="contenitore-testo-annotato">
<div id="contenitore-testo-annotato">
我该怎么做才能生成交替的 html 标签? 如何选择连接到相关图像的文本段?
最佳答案
解决方法如下:
为tei:text定义一个空模板,这样处理就不会自动流入其中:
<xsl:template match="tei:text" />
为源文档中的所有面板创建一个变量,以便您可以简洁高效地访问它们:
<xsl:variable name="pannelli" select="/*/tei:text/tei:body/tei:div[@type='panelGrp']" />
处理传真表面时,确定该表面在文档中的序号,并使用它来将模板应用到相关面板:
<xsl:template match="tei:facsimile/tei:surface">
<xsl:variable name="pos">
<xsl:number count="tei:facsimile/tei:surface" level="any"/>
</xsl:variable>
<div id="contenitore-immagine">
<img class="dimensioni" src="{tei:graphic/@url}"/>
</div>
<xsl:apply-templates select="$pannelli[number($pos)]" />
</xsl:template>
(与原题无关)对panelGrp模板做一些改进和修正:
<xsl:template match="tei:body/tei:div[@type='panelGrp']">
<div id="contenitore-testo-annotato">
<ul class="ul-testo-annotato">
<xsl:apply-templates select="tei:panel" />
</ul>
</div>
</xsl:template>
<xsl:template match="tei:div[@type='panelGrp']/tei:panel">
<li class="li-testo-annotato">
<p class="p-testo-annotato">
<xsl:value-of select="tei:balloon"/>
</p>
</li>
</xsl:template>
完整解决方案:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:cbml="http://www.cbml.org/ns/1.0"
exclude-result-prefixes="tei cbml">
<xsl:output method="html" version="4.0" indent="no"/>
<xsl:template match="/">
<xsl:text disable-output-escaping='yes'><!DOCTYPE html></xsl:text>
<html>
<head>
<title>
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:title"/>
</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="stile.css" />
</head>
<body>
<div class="inner-container">
<div id="corpo">
<xsl:apply-templates/>
</div>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="tei:teiHeader">
<div id="header">
<h1 id="titolo">
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:title"/>
</h1>
<h3 id="resp-name">
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:respStmt/tei:resp"/>
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:respStmt/tei:name"/>
</h3>
</div>
<div id="contenitore-tei-header">
<div id="informazioni-codifica">
<h3 class="titolo-liste">Informazioni sulla codifica</h3>
<h5>
<xsl:value-of select="concat('Titolo: ', tei:fileDesc/tei:titleStmt/tei:title)"/>
</h5>
<h5>
<xsl:value-of select="concat('Codifica curata da: ', tei:fileDesc/tei:titleStmt/tei:respStmt/tei:persName)"/>
</h5>
<h5>
<xsl:value-of select="concat('Publisher:', tei:fileDesc/tei:publicationStmt/tei:publisher)"/>
</h5>
<h5>
<xsl:value-of select="concat('Città:', tei:fileDesc/tei:publicationStmt/tei:pubPlace)"/>
</h5>
<h5>
<xsl:value-of select="concat('Data: ', tei:fileDesc/tei:publicationStmt/tei:date)"/>
</h5>
</div>
<div id="informazioni-fumetto">
<h3 class="titolo-liste">Informazioni sul fumetto</h3>
<h5>
<xsl:value-of select="concat('Titolo originale: ', tei:fileDesc/tei:sourceDesc/tei:bibl/tei:title)"/>
</h5>
<h5>
<xsl:text>Autori: </xsl:text>
<a href="item.php?id={ItemId}">
<xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:bibl/tei:author/tei:persName"/>
</a>
</h5>
<h5>
<xsl:value-of select="concat('Casa editrice: ', tei:fileDesc/tei:sourceDesc/tei:bibl/tei:publisher)"/>
</h5>
<h5>
<xsl:value-of select="concat('Città: ', tei:fileDesc/tei:sourceDesc/tei:bibl/tei:pubPlace)"/>
</h5>
<h5>
<xsl:value-of select="concat('Data pubblicazione: ', tei:fileDesc/tei:sourceDesc/tei:bibl/tei:date)"/>
</h5>
</div>
<div id="introduzione">
<h3 class="titolo-liste">Introduzione</h3>
<xsl:value-of select="tei:encodingDesc/tei:projectDesc"/>
</div>
</div>
</xsl:template>
<xsl:template match="tei:text" />
<xsl:variable name="pannelli" select="/*/tei:text/tei:body/tei:div[@type='panelGrp']" />
<xsl:template match="tei:facsimile/tei:surface">
<xsl:variable name="pos">
<xsl:number count="tei:facsimile/tei:surface" level="any"/>
</xsl:variable>
<div id="contenitore-immagine">
<img class="dimensioni" src="{tei:graphic/@url}"/>
</div>
<xsl:apply-templates select="$pannelli[number($pos)]" />
</xsl:template>
<xsl:template match="tei:body/tei:div[@type='panelGrp']">
<div id="contenitore-testo-annotato">
<ul class="ul-testo-annotato">
<xsl:apply-templates select="tei:panel" />
</ul>
</div>
</xsl:template>
<xsl:template match="tei:div[@type='panelGrp']/tei:panel">
<li class="li-testo-annotato">
<p class="p-testo-annotato">
<xsl:value-of select="tei:balloon"/>
</p>
</li>
</xsl:template>
</xsl:stylesheet>
关于html - Xsl/Xml 问题结构生成html标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29171792/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search