The following PHP code example shows how you transform XML data into the Open XML format. The code uses a DOMDocument object to load the XSLT and create an XSLTProcessor. The XSLTPRocessor’s transformToXML method is called to transform the XML data into the Open XML Wordprocessing format.
//Load the xml data and xslt and perform the transformation. $xmlDocument = new DOMDocument(); $xmlDocument->load($xmlDataFile); $xsltDocument = new DOMDocument(); $xsltDocument->load($xsltFile); $xsltProcessor = new XSLTProcessor(); $xsltProcessor->importStylesheet($xsltDocument); //After the transformation $newContentNew contains //the XML data in the Open XML Wordprocessing format. $newContent = $xsltProcessor->transformToXML($xmlDocument);The following PHP example shows creating the output Word 2007 document. Open XML files are packaged following the Open Packaging Convention and can be treated as Zip files. A ZipArchive object is used to open the Word 2007 document for editing.
//Copy the Word 2007 template document to the output file. if (copy($sourceTemplate, $outputDocument)) { //Open XML files are packaged following the Open Packaging //Conventions and can be treated as zip files when //accessing their content. $zipArchive = new ZipArchive(); $zipArchive->open($outputDocument);The contents of a Word 2007 document are stored in the document.xml file. The following PHP code example shows how to update the Word 2007 document by using the content that contains the XML data by replacing the document.xml file and then closing the ZipArchive to save the changes.
//Replace the content with the new content created above. //In the Open XML Wordprocessing format content is stored //in the document.xml file located in the word directory. $zipArchive->addFromString("word/document.xml", $newContent); $zipArchive->close();
XSLTを作るのがかなり大変。でも、rst2xml 用のスタイルシートを1回作れば幸せになれるかもしれない。
Posted via web from 原宿工業大学 | Comment »
フォームのフィールド名の先頭に “clean_”をつけたメソッドを定義します。
# -*- coding: utf-8 -*-
from django import forms
from django.contrib.formtools.preview import FormPreview
from django.http import HttpResponseRedirect
import re
class MessageForm(forms.Form):
message = forms.CharField() def clean_message(self):
_c_message = self.cleaned_data[‘message’]
if re.match(“^\d+$”,_c_message) == None:
raise forms.ValidationError(u’数字を入力してください’)
else:
return _c_message
アルファベットでPreviewすると、エラー
数字でPreviewだとOK
Posted via email from 原宿工業大学 | Comment »
FormPreviewのクラス変数に定義するだけ。
from django import forms
from django.contrib.formtools.preview import FormPreview
from django.http import HttpResponseRedirect class MessageForm(forms.Form):
message = forms.CharField() class MessageFormPreview(FormPreview):
preview_template = ‘djcube/signup_preview.html’
form_template = ‘djcube/signup.html’ def done(self, request, cleaned_data):
return HttpResponseRedirect(‘/’)
Posted via email from 原宿工業大学 | Comment »



